Skip to content

Commit

Permalink
feat: add koios subscription auth
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Kungla <[email protected]>
  • Loading branch information
mkungla committed May 30, 2024
1 parent acbd2f9 commit 2c99eb3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
5 changes: 4 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type (
client *http.Client
commonHeaders http.Header
locked bool
auth *AuthInfo
}
)

Expand Down Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion koios.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -158,6 +160,8 @@ type (

// ReqDurStr String representation of ReqDur.
ReqDurStr string `json:"req_dur_str,omitempty"`

Auth AuthInfo `json:"auth"`
}
)

Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down

0 comments on commit 2c99eb3

Please sign in to comment.