Files
email-api-client/client/client.go
Ron Rise 847fcfd0b8
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 22s
refactor: update package paths and improve client context handling
2025-06-25 11:13:08 -04:00

61 lines
946 B
Go
Executable File

package client
import "context"
type Client struct {
config *Configuration
token *Token
}
type contextKeyType string
var contextKey contextKeyType = "client"
type accessTokenRequest struct {
GrantType string `json:"grant_type"`
ClientId string `json:"client_id"`
ClientSecret string `json:"client_secret"`
}
func NewClient(config *Configuration) *Client {
client := &Client{
config: config,
}
token, err := getToken(client.config)
if err != nil {
return nil
}
client.token = token
return client
}
func FromContext(ctx context.Context) *Client {
client := ctx.Value(contextKey)
if client == nil {
return nil
}
if c, ok := client.(*Client); ok {
return c
}
return nil
}
func NewWithContext(ctx context.Context) context.Context {
client := ctx.Value(contextKey)
if client == nil {
return ctx
}
if c, ok := client.(*Client); ok {
return context.WithValue(ctx, contextKey, c)
}
return ctx
}