Help us shape the future of Go! Take the 2026 Go Developer Survey

api

package
v0.0.0-...-c19bbba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 3, 2020 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package api provides a basic client library for the Sourcegraph API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NullInt

func NullInt(n int) *int

NullInt returns a nullable int for use in a GraphQL variable, where -1 is treated as a nil value.

func NullString

func NullString(s string) *string

NullString returns a nullable string for use in a GraphQL variable, where "" is treated as a nil value.

Types

type Client

type Client interface {
	// NewQuery is a convenience method to create a GraphQL request without
	// variables.
	NewQuery(query string) Request

	// NewRequest creates a GraphQL request.
	NewRequest(query string, vars map[string]interface{}) Request

	// NewHTTPRequest creates an http.Request for the Sourcegraph API.
	//
	// path is joined against the API route. For example on Sourcegraph.com this
	// will result the URL: https://sourcegraph.com/.api/path.
	NewHTTPRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)
}

Client instances provide methods to create API requests.

func NewClient

func NewClient(opts ClientOpts) Client

NewClient creates a new API client.

type ClientOpts

type ClientOpts struct {
	Endpoint          string
	AccessToken       string
	AdditionalHeaders map[string]string

	// Flags are the standard API client flags provided by NewFlags. If nil,
	// default values will be used.
	Flags *Flags

	// Out is the writer that will be used when outputting diagnostics, such as
	// curl commands when -get-curl is enabled.
	Out io.Writer
}

ClientOpts encapsulates the options given to NewClient.

type Flags

type Flags struct {
	// contains filtered or unexported fields
}

Flags encapsulates the standard flags that should be added to all commands that issue API requests.

func NewFlags

func NewFlags(flagSet *flag.FlagSet) *Flags

NewFlags instantiates a new Flags structure and attaches flags to the given flag set.

type Request

type Request interface {
	// Do actions the request. Normally, this means that the request is
	// transmitted and the response is unmarshalled into result.
	//
	// If no data was available to be unmarshalled — for example, due to the
	// -get-curl flag being set — then ok will return false.
	Do(ctx context.Context, result interface{}) (ok bool, err error)

	// DoRaw has the same behaviour as Do, with one exception: the result will
	// not be unwrapped, and will include the GraphQL errors. Therefore the
	// structure that is provided as the result should have top level Data and
	// Errors keys for the GraphQL wrapper to be unmarshalled into.
	DoRaw(ctx context.Context, result interface{}) (ok bool, err error)
}

Request instances represent GraphQL requests.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL