initial commit

This commit is contained in:
Mike Mason
2023-07-01 00:04:52 +00:00
commit 80fb879ef6
65 changed files with 3544 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
package emgql
import (
"net/url"
"go.uber.org/zap"
)
// Option is a Client configuration Option definition.
type Option func(c *Client) error
// WithLogger sets the logger for the client.
func WithLogger(logger *zap.SugaredLogger) Option {
return func(c *Client) error {
c.logger = logger
return nil
}
}
// WithBaseURL updates the baseurl used by the client.
func WithBaseURL(baseURL string) Option {
return func(c *Client) error {
u, err := url.Parse(baseURL)
if err != nil {
return err
}
c.baseURL = u
return nil
}
}
// WithConfig applies all configurations defined in the config.
func WithConfig(config Config) Option {
return func(c *Client) error {
var options []Option
if config.BaseURL != "" {
options = append(options, WithBaseURL(config.BaseURL))
}
for _, opt := range options {
if err := opt(c); err != nil {
return err
}
}
return nil
}
}