這是一個建立於
的文章,其中的資訊可能已經有所發展或是發生改變。
寫在前面
我是一個Golang程式員,基本上我所有的東西都是用Go開發的。前不久想給我的個人網站接入搜尋功能,使用了Swiftype這個工具。然而我發現它並沒有Golang的API工具包。在GitHub上面找了一個包,卻發現有bug不能用,遂自己fork了代碼搞一套。
源碼地址:https://github.com/mnhkahn/swiftype
安裝
go get -v gopkg.in/mnhkahn/swiftype.v1
文檔
文檔可以在godoc上面查看。目前只支援搜尋方法,因為我這邊也只用這個,如果未來我這邊有別的API需求,會考慮更新。
type Client
- func NewClientWithApiKey(api_key string, host string) *Client
- func NewClientWithUsernamePassword(username string, password string, host string) *Client
- func (c *Client) Engine(engine string) ([]byte, error)
- func (c *Client) Engines() ([]byte, error)
- func (c Client) Search(engine string, query string) (SwiftypeResult, error)
type SwiftypeResult
例子
SWIFTYPE := *swiftype.ClientSWIFTYPE_APIKEY := "YOUR OWN API KEY"SWIFTYPE_HOST := "api.swiftype.com"SWIFTYPE_ENGINE := "YOUR OWN ENGINE"SWIFTYPE := swiftype.NewClientWithApiKey(SWIFTYPE_APIKEY, SWIFTYPE_HOST)data, err := SWIFTYPE.Search(SWIFTYPE_ENGINE, q)if err != nil { panic(err)}_ = data
原文連結:Swiftype的Golang API 發布!,轉載請註明來源!