Documentation ¶
Overview ¶
Package giant provides for reuse of comman json api client patterns while doing its best to not get in the way :)
Index ¶
- type Config
- type Giant
- func (giant *Giant) Send(ctx context.Context, rq Request) (response *http.Response, err error)
- func (giant *Giant) SendJson(ctx context.Context, method, path string, body io.Reader) (data []byte, err error)
- func (giant *Giant) SendObject(ctx context.Context, method, path string, sndObj, rcvObj any) (err error)
- func (giant *Giant) Use(tripper Tripper)
- type Logger
- type Redact
- type Request
- type Tripper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // BaseUri is the scheme, domain, optionally port and/or path // though which the client connects to a webserver // for example: http://192.168.64.3:4080/graphql BaseUri string `json:"base_uri" desc:"ex: http://llp.org:4080/graphql" required:"true"` // Timeout is the overall request timeout Timeout time.Duration `json:"timeout" desc:"request timeout" default:"1m"` // TimeoutShort is the dialer and response header timeout TimeoutShort time.Duration `json:"timeout_short" desc:"dialer and header timeout" default:"10s"` // Headers are set when making a request Headers []string `json:"headers,omitempty" desc:"header pairs to be sent with every request"` // SkipVerify skips verification of ssl certificates (dev only pls!) SkipVerify bool `json:"skip_verify" desc:"skip cert verification"` // User is for basic auth in NewWithTrippers. User string `json:"user,omitempty" desc:"username for basic auth"` // Pass is for basic auth in NewWithTrippers. Pass Redact `json:"pass,omitempty" desc:"password for basic auth"` // RedactHeaders are headers to be redacted from logging in NewWithTrippers. RedactHeaders []string `json:"redact_headers,omitempty" desc:"headers to redact from request logging"` // SkipBody when true request and response bodies are not logged in NewWithTrippers.. SkipBody bool `json:"skip_body" desc:"skip logging of body for request and response"` }
Config represents giant config
func (*Config) NewWithTrippers ¶ added in v0.0.2
NewWithTrippers is a convenience method that adds StatusRt and Logrt after creating a client. If User and Pass are defined in Config BasicRt is added as well.
type Giant ¶
type Giant struct { // Client is a stdlib http client Client http.Client // BaseUri is as described in Config BaseUri string // Headers are set when making a request Headers map[string]string }
Giant represents an http client
func (*Giant) SendJson ¶
func (giant *Giant) SendJson(ctx context.Context, method, path string, body io.Reader) (data []byte, err error)
SendJson constructs a request, sends and recieves json closing the response body
type Redact ¶ added in v0.0.2
type Redact string
Redact is a type for private strings
func (Redact) MarshalJSON ¶ added in v0.0.2
MarshalJSON implements the Marshaler interface
type Request ¶
type Request struct { // Method is one of the http RFC methods (no net!) Method string // Path is appended to BaseUri when making a request // (leading and trailing slashes recommended here, convention for sanity!) Path string // Body is read from when making a request Body io.Reader // Headers are set when making a request Headers map[string]string }
Request represents an http request
type Tripper ¶
type Tripper interface { http.RoundTripper Wrap(next http.RoundTripper) }
Directories ¶
Path | Synopsis |
---|---|
Package basicrt implements the Tripper interface, adding a Basic Auth header.
|
Package basicrt implements the Tripper interface, adding a Basic Auth header. |
examples
|
|
weather
Package main demonstrates use of a client service layer built with giant
|
Package main demonstrates use of a client service layer built with giant |
weather/svc
Package svc demonstrates a client service layer built with giant
|
Package svc demonstrates a client service layer built with giant |
Package logrt holds space for an implementation of http.RoundTripper that logs requests and responses.
|
Package logrt holds space for an implementation of http.RoundTripper that logs requests and responses. |
Package statusrt implements the Tripper interface returning an error if the reponse status code is not in the 200's
|
Package statusrt implements the Tripper interface returning an error if the reponse status code is not in the 200's |
Click to show internal directories.
Click to hide internal directories.