Example #1
0
func SendGremlinQuery(auth *shttp.AuthenticationOpts, query string) (io.ReadCloser, error) {
	client, err := shttp.NewRestClientFromConfig(auth)
	if err != nil {
		return nil, err
	}

	gq := api.Topology{GremlinQuery: query}
	s, err := json.Marshal(gq)
	if err != nil {
		return nil, err
	}

	contentReader := bytes.NewReader(s)

	resp, err := client.Request("POST", "api/topology", contentReader)
	if err != nil {
		return nil, err
	}

	if resp.StatusCode != http.StatusOK {
		data, _ := ioutil.ReadAll(resp.Body)
		return nil, fmt.Errorf("%s: %s", resp.Status, string(data))
	}

	return resp.Body, nil
}
Example #2
0
func NewRestClientFromConfig(authOptions *shttp.AuthenticationOpts) (*shttp.RestClient, error) {
	return shttp.NewRestClientFromConfig(authOptions)
}