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 ¶
NullInt returns a nullable int for use in a GraphQL variable, where -1 is treated as a nil value.
func NullString ¶
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.
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.
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.
Click to show internal directories.
Click to hide internal directories.