61 lines
1.1 KiB
Go
61 lines
1.1 KiB
Go
// Package client provides a Go client for interacting with the MCIAS (Metacircular Identity and Access System).
|
|
package client
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// Client encapsulates the connection details and authentication state needed to interact with the MCIAS API.
|
|
type Client struct {
|
|
BaseURL string
|
|
HTTPClient *http.Client
|
|
Token string
|
|
Username string
|
|
}
|
|
|
|
type Option func(*Client)
|
|
|
|
func WithBaseURL(baseURL string) Option {
|
|
return func(c *Client) {
|
|
c.BaseURL = baseURL
|
|
}
|
|
}
|
|
|
|
func WithHTTPClient(httpClient *http.Client) Option {
|
|
return func(c *Client) {
|
|
c.HTTPClient = httpClient
|
|
}
|
|
}
|
|
|
|
func WithToken(token string) Option {
|
|
return func(c *Client) {
|
|
c.Token = token
|
|
}
|
|
}
|
|
|
|
func WithUsername(username string) Option {
|
|
return func(c *Client) {
|
|
c.Username = username
|
|
}
|
|
}
|
|
|
|
func NewClient(options ...Option) *Client {
|
|
client := &Client{
|
|
BaseURL: "http://localhost:8080",
|
|
HTTPClient: &http.Client{
|
|
Timeout: 10 * time.Second,
|
|
},
|
|
}
|
|
|
|
for _, option := range options {
|
|
option(client)
|
|
}
|
|
|
|
return client
|
|
}
|
|
|
|
func (c *Client) IsAuthenticated() bool {
|
|
return c.Token != ""
|
|
}
|