refactor(client): drop With prefix from options
Amolith
created 3 weeks ago
Functional options now use plain names (HTTPClient, BaseURL, UserAgent)
to distinguish them from builder pattern methods (WithNote, WithStatus).
Updated package docs and README with UserAgent example.
Assisted-by: Claude Opus 4.5 via Crush
Change summary
README.md | 2 +-
lunatask.go | 14 +++++++-------
2 files changed, 8 insertions(+), 8 deletions(-)
Detailed changes
@@ -44,7 +44,7 @@ import (
)
func main() {
- client := lunatask.NewClient(os.Getenv("LUNATASK_TOKEN"))
+ client := lunatask.NewClient(os.Getenv("LUNATASK_TOKEN"), lunatask.UserAgent("MyApp/1.0"))
// Verify credentials
if _, err := client.Ping(context.Background()); err != nil {
@@ -4,7 +4,7 @@
// Package lunatask provides a Go client for the Lunatask API.
//
-// client := lunatask.NewClient(os.Getenv("LUNATASK_TOKEN"))
+// client := lunatask.NewClient(os.Getenv("LUNATASK_TOKEN"), lunatask.UserAgent("MyApp/1.0"))
// if _, err := client.Ping(ctx); err != nil {
// log.Fatal(err)
// }
@@ -145,23 +145,23 @@ type Client struct {
// Option configures a Client.
type Option func(*Client)
-// WithHTTPClient sets a custom HTTP client.
-func WithHTTPClient(client *http.Client) Option {
+// HTTPClient sets a custom HTTP client.
+func HTTPClient(client *http.Client) Option {
return func(c *Client) {
c.httpClient = client
}
}
-// WithBaseURL sets a custom base URL (useful for testing).
-func WithBaseURL(url string) Option {
+// BaseURL sets a custom base URL (useful for testing).
+func BaseURL(url string) Option {
return func(c *Client) {
c.baseURL = url
}
}
-// WithUserAgent sets a custom User-Agent prefix.
+// UserAgent sets a custom User-Agent prefix.
// The library identifier (go-lunatask/version) is always appended.
-func WithUserAgent(ua string) Option {
+func UserAgent(ua string) Option {
return func(c *Client) {
c.userAgent = ua
}