Documentation ¶
Overview ¶
go-appbase is a data streams library for Go,
compatible with Elasticsearch.
To use the data streaming facilities of the library, create an account at https://appbase.io/.
Checkout the examples to learn more.
Example ¶
// Importing the library as 'github.com/appbase/go-appbase'. // Then instantiate the client with appbase.NewClient(url, username, password, appname). client, _ = NewClient("https://scalr.api.appbase.io", "HnnFbzaRq", "5d2ba0c3-4689-46f7-8cc9-60473479dc71", "go-appbase-tests") err := client.Ping() if err != nil { log.Fatalln(err) } fmt.Println("Client created")
Output: Client created
Index ¶
- func NewWebhook() *actions.Webhook
- type Client
- func (c *Client) Delete() *actions.DeleteService
- func (c *Client) Get() *actions.GetService
- func (c *Client) GetStream() *actions.GetStreamService
- func (c *Client) Index() *actions.IndexService
- func (c *Client) Ping() error
- func (c *Client) Search() *actions.SearchService
- func (c *Client) SearchStream() *actions.SearchStreamService
- func (c *Client) SearchStreamToURL() *actions.SearchStreamToURLService
- func (c *Client) Update() *actions.UpdateService
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewWebhook ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func (*Client) Delete ¶
func (c *Client) Delete() *actions.DeleteService
Delete returns a DeleteService which is used to delete a document
func (*Client) Get ¶
func (c *Client) Get() *actions.GetService
Get returns a GetService which is used to retrieve a document
func (*Client) GetStream ¶
func (c *Client) GetStream() *actions.GetStreamService
GetStream is used to start a stream of updates corresponding to a document
func (*Client) Index ¶
func (c *Client) Index() *actions.IndexService
Index returns an IndexService which is used to index a document
Example ¶
const testtype string = "tweet" const tweet string = `{"user":"jack","message":"just setting up my twttr"}` res, err := client.Index().Type(testtype).Id("3").Body(tweet).Do() if err != nil { log.Fatalln(err) return } fmt.Println(res.Id)
Output: 3
func (*Client) Search ¶
func (c *Client) Search() *actions.SearchService
Search provides access to Elasticsearch's search functionality
Example ¶
const testtype string = "tweet" const matchAllQuery string = `{"query":{"match_all":{}}}` res, err := client.Search().Type(testtype).Body(matchAllQuery).Do() if err != nil { log.Fatalln(err) return } fmt.Println(res.Hits.TotalHits > 0)
Output: true
func (*Client) SearchStream ¶
func (c *Client) SearchStream() *actions.SearchStreamService
SearchStream is used to get updates corresponding to a query
Example ¶
const testtype string = "tweet" const matchAllQuery string = `{"query":{"match_all":{}}}` const anotherTweet string = `{"user":"ev","message":"twttr's way better than odeo"}` searchStreamResponse, err := client.SearchStream().Type(testtype).Body(matchAllQuery).Do() if err != nil { log.Fatalln(err) return } _, err = client.Index().Type(testtype).Id("3").Body(anotherTweet).Do() if err != nil { log.Fatalln(err) return } docResponse, err := searchStreamResponse.Next() if err != nil { log.Fatalln(err) return } fmt.Println(docResponse.Id)
Output: 3
func (*Client) SearchStreamToURL ¶
func (c *Client) SearchStreamToURL() *actions.SearchStreamToURLService
SearchStream is used to send updates corresponding to a query to an URL
Example ¶
// Similar to NewClient, we will instiate a webhook instance with appbase.NewWebhook() webhook := NewWebhook() // Webhook instancess need to have a URL, method and body (which can be string or a JSON object) webhook.URL = "https://www.mockbin.org/bin/cd6461ab-468f-42f5-865f-4eed22daae95" webhook.Method = "POST" webhook.Body = "hellowebhooks" const testtype string = "tweet" const matchAllQuery string = `{"query":{"match_all":{}}}` searchStreamToURLResponse, err := client.SearchStreamToURL().Type(testtype).Query(matchAllQuery).AddWebhook(webhook).Do() if err != nil { log.Fatalln(err) return } stopSearchStream, err := searchStreamToURLResponse.Stop() if err != nil { log.Fatalln(err) return } fmt.Println(searchStreamToURLResponse.Id == stopSearchStream.Id)
Output: true
func (*Client) Update ¶
func (c *Client) Update() *actions.UpdateService
Update returns an UpdateService which is used to update a document
Example ¶
const testtype string = "tweet" const altTweet string = `{"user":"jack","message":"or just forget it, kate's yoga classes are more fun"}` res, err := client.Update().Type(testtype).Id("3").Body(fmt.Sprintf(`{ "doc": %s }`, altTweet)).Do() if err != nil { log.Fatalln(err) return } fmt.Println(res.Id)
Output: 3