diff --git a/client.go b/client.go index 62d3690..df99b72 100644 --- a/client.go +++ b/client.go @@ -27,6 +27,7 @@ type ( client *http.Client commonHeaders http.Header locked bool + auth *AuthInfo } ) @@ -195,7 +196,9 @@ func (c *Client) applyReqHeaders(req *http.Request, headers http.Header) { } func (c *Client) requestWithStats(req *http.Request, res *Response) (*http.Response, error) { - res.Stats = &RequestStats{} + res.Stats = &RequestStats{ + Auth: c.getAuth(), + } var dns, tlshs, connect time.Time req = req.WithContext( httptrace.WithClientTrace( diff --git a/koios.go b/koios.go index 980c8ee..e89a50b 100644 --- a/koios.go +++ b/koios.go @@ -48,7 +48,8 @@ const ( // DefaultOrigin is default origin header used by api client. DefaultOrigin = "https://github.com/cardano-community/koios-go-client/v4" // PageSize is default page size used by api client. - PageSize uint = 1000 + PageSize uint = 1000 + DefaultTimeout = 30 * time.Second ) // Predefined errors used by the library. @@ -76,6 +77,7 @@ var ( ErrClientLocked = errors.New("client is locked") ErrNoScriptHash = errors.New("missing script hash(es)") ErrNoUTxORef = errors.New("missing UTxO reference(s)") + ErrAuth = errors.New("auth error") // ZeroLovelace is alias decimal.Zero. ZeroLovelace = decimal.Zero.Copy() //nolint: gochecknoglobals @@ -158,6 +160,8 @@ type ( // ReqDurStr String representation of ReqDur. ReqDurStr string `json:"req_dur_str,omitempty"` + + Auth AuthInfo `json:"auth"` } ) @@ -178,6 +182,7 @@ type ( func New(opts ...Option) (*Client, error) { c := &Client{ commonHeaders: make(http.Header), + auth: &AuthInfo{}, } // set default base url _ = c.setBaseURL(DefaultScheme, MainnetHost, DefaultAPIVersion, DefaultPort) diff --git a/options.go b/options.go index 7d17a50..1eddb6c 100644 --- a/options.go +++ b/options.go @@ -82,7 +82,7 @@ func HTTPClient(client *http.Client) Option { if c.locked { return ErrClientLocked } - timeout := time.Second * 60 + timeout := DefaultTimeout if client == nil { client = &http.Client{} }