Junie: cleanups. Code fixups.
This commit is contained in:
@@ -6,54 +6,41 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
// Client is the main struct for interacting with the MCIAS API.
|
||||
// Client encapsulates the connection details and authentication state needed to interact with the MCIAS API.
|
||||
type Client struct {
|
||||
// BaseURL is the base URL of the MCIAS server.
|
||||
BaseURL string
|
||||
|
||||
// HTTPClient is the HTTP client used for making requests.
|
||||
BaseURL string
|
||||
HTTPClient *http.Client
|
||||
|
||||
// Token is the authentication token.
|
||||
Token string
|
||||
|
||||
// Username is the authenticated username.
|
||||
Username string
|
||||
Token string
|
||||
Username string
|
||||
}
|
||||
|
||||
// ClientOption is a function that configures a Client.
|
||||
type ClientOption func(*Client)
|
||||
type Option func(*Client)
|
||||
|
||||
// WithBaseURL sets the base URL for the client.
|
||||
func WithBaseURL(baseURL string) ClientOption {
|
||||
func WithBaseURL(baseURL string) Option {
|
||||
return func(c *Client) {
|
||||
c.BaseURL = baseURL
|
||||
}
|
||||
}
|
||||
|
||||
// WithHTTPClient sets the HTTP client for the client.
|
||||
func WithHTTPClient(httpClient *http.Client) ClientOption {
|
||||
func WithHTTPClient(httpClient *http.Client) Option {
|
||||
return func(c *Client) {
|
||||
c.HTTPClient = httpClient
|
||||
}
|
||||
}
|
||||
|
||||
// WithToken sets the authentication token for the client.
|
||||
func WithToken(token string) ClientOption {
|
||||
func WithToken(token string) Option {
|
||||
return func(c *Client) {
|
||||
c.Token = token
|
||||
}
|
||||
}
|
||||
|
||||
// WithUsername sets the username for the client.
|
||||
func WithUsername(username string) ClientOption {
|
||||
func WithUsername(username string) Option {
|
||||
return func(c *Client) {
|
||||
c.Username = username
|
||||
}
|
||||
}
|
||||
|
||||
// NewClient creates a new MCIAS client with the given options.
|
||||
func NewClient(options ...ClientOption) *Client {
|
||||
func NewClient(options ...Option) *Client {
|
||||
client := &Client{
|
||||
BaseURL: "http://localhost:8080",
|
||||
HTTPClient: &http.Client{
|
||||
@@ -68,7 +55,6 @@ func NewClient(options ...ClientOption) *Client {
|
||||
return client
|
||||
}
|
||||
|
||||
// IsAuthenticated returns true if the client has a token.
|
||||
func (c *Client) IsAuthenticated() bool {
|
||||
return c.Token != ""
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user