Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type API ¶
type API = GenericAPI[generated.GQLClient]
API is a type alias for GenericAPI[generated.GQLClient]. The generated.GQLClient is generated based on graphQL query schema in this module.
type ContentType ¶
type ContentType string
ContentType is an enum for the content type of a request.
const ( // ContentTypeJson is the content type for a request with a json body in utf-8. ContentTypeJson ContentType = "application/json; charset=UTF-8" )
type GQLClient ¶
type GQLClient interface{}
GQLClient defines the interface for the generated graphQL client.
type GenericAPI ¶
type GenericAPI[T GQLClient] struct { GQLClient T RestClient RestClient }
GenericAPI is a generic api client that uses a generated GQLClient and a default http RestClient.
func NewGenericAPI ¶
func NewGenericAPI[T GQLClient](newGQLClientFunc NewGQLClientFunc[T], gqlEndpoint string, restEndpoint string, headers RequestHeaders) GenericAPI[T]
NewGenericAPI takes a NewGQLClientFunc, a gqlEndpoint for the GQLClient, a restEndpoint for the RestClient, and request headers. The request headers are set the same for both clients. NewGenericAPI returns an GenericAPI interface. Example:
api := NewGenericAPI[generated.GQLClient](generated.NewClient, "<gqlEndpoint>", "<restEndpoint>", RequestHeaders{WithAuthToken("<authToken>")})
func (GenericAPI[T]) GetGQLClient ¶
func (r GenericAPI[T]) GetGQLClient() T
GetGQLClient returns the GQLClient.
func (GenericAPI[T]) GetRestClient ¶
func (r GenericAPI[T]) GetRestClient() RestClient
GetRestClient returns the RestClient.
func (GenericAPI[T]) ProcessGQLError ¶
func (r GenericAPI[T]) ProcessGQLError(err error) error
ProcessGQLError takes an error returned by the GQLClient, improve it's message formatting and returns it.
type GenericProvider ¶
type GenericProvider[T GQLClient] interface { GetGQLClient() T GetRestClient() RestClient ProcessGQLError(err error) error }
GenericProvider is an interface for an api instance. The api instance should have a generated GQLClient and a default http RestClient. The api object should implement ProcessGQLError to process a GQLError
type NewGQLClientFunc ¶
type NewGQLClientFunc[T GQLClient] func(cli *http.Client, baseURL string, options *clientv2.Options, interceptors ...clientv2.RequestInterceptor) T
NewGQLClientFunc defines the signature of the generated function that creates a new GQLClient. The function is generated from the [gqlgenc] tool. [gqlgenc]: https://github.com/Yamashou/gqlgenc
type Provider ¶
type Provider GenericProvider[generated.GQLClient]
Provider is a type alias for GenericProvider[generated.GQLClient].
type RequestHeader ¶
RequestHeader defines a request header for a http request.
func WithAuthHeader ¶
func WithAuthHeader(authToken string) RequestHeader
WithAuthHeader returns a RequestHeader with the key "Authorization" and the value of the authToken.
func WithContentType ¶
func WithContentType(contentType ContentType) RequestHeader
WithContentType returns a RequestHeader with the key "Content-Type" and the string value of the contentType enum.
type RequestHeaders ¶
type RequestHeaders = []RequestHeader
RequestHeaders defines a list of RequestHeader(s).
type RestClient ¶
type RestClient struct {
// contains filtered or unexported fields
}
RestClient defines the interface for the default http client.
func (*RestClient) NewRequest ¶
func (r *RestClient) NewRequest(method string, uri string, headers RequestHeaders, body []byte) (request *http.Request, err error)
NewRequest takes a method, uri, request headers and body. if the request needs an empty body, like for a GET request, just pass in an empty list of bytes.
func (*RestClient) ReadResponseJson ¶
func (r *RestClient) ReadResponseJson(response *http.Response, v any) error
ReadResponseJson reads the response body and unmarshals it into the given interface.