Skip to content

Commit

Permalink
refactor: cleanup sifi.NewClient to match sifi internal patterns
Browse files Browse the repository at this point in the history
  • Loading branch information
masonkatz committed Feb 22, 2024
1 parent 8a07442 commit ad365fd
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions sifi/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"log/slog"

"github.com/softiron/hypercloud-api/client"
"github.com/softiron/hypercloud-api/cloud"
Expand All @@ -21,19 +22,46 @@ type Client struct {
*client.Client
}

// WithLogger is an option setting function for NewClient that sets the logger
// on the underlying generic http client.
func WithLogger(logger *slog.Logger) func(*client.Client) {
return func(c *client.Client) {
c.Logger = logger
}
}

// WithUserAgent is an option setting function for NewClient that sets the
// user-agent on the underlying generic http client.
func WithUserAgent(ua string) func(*client.Client) {
return func(c *client.Client) {
c.UserAgent = ua
}
}

// WithDebug is an option setting function for NewClient that sets the debug
// mode on the underlying generic http client.
func WithDebug(b bool) func(*client.Client) {
return func(c *client.Client) {
c.Debug = b
}
}

// NewClient returns a new client.
func NewClient(o *client.Options) *Client {
func NewClient(o *client.Options, fn ...func(*client.Client)) *Client {
c := client.New(o)
c.NewError = newError

for _, f := range fn {
f(c)
}

prefix := APIPrefix + "/" + APIVersion

return &Client{
Cloud: cloud.NewService(c, prefix),
Metal: metal.NewService(c, prefix),
Snapshot: snapshot.NewService(c, prefix),

Client: c,
Client: c,
}
}

Expand Down

0 comments on commit ad365fd

Please sign in to comment.