refactor: update package paths and improve client context handling
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 22s

This commit is contained in:
2025-06-25 11:13:08 -04:00
parent 70ea3e2025
commit 847fcfd0b8
8 changed files with 181 additions and 26 deletions

View File

@@ -1,14 +1,15 @@
package client
import "context"
type Client struct {
config *Configuration
token *Token
}
var c = struct {
client *Client
initialized bool
}{}
type contextKeyType string
var contextKey contextKeyType = "client"
type accessTokenRequest struct {
GrantType string `json:"grant_type"`
@@ -18,10 +19,6 @@ type accessTokenRequest struct {
func NewClient(config *Configuration) *Client {
if c.initialized {
return c.client
}
client := &Client{
config: config,
}
@@ -33,7 +30,31 @@ func NewClient(config *Configuration) *Client {
client.token = token
c.client = client
return c.client
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
}

View File

@@ -1,7 +1,7 @@
package client
import (
"git.s.int/packages/go/utilities/Env"
"gitea.siteworxpro.com/golang-packages/utilities/Env"
"log"
)

View File

@@ -3,7 +3,7 @@ package client
import (
"bytes"
"encoding/json"
"git.s.int/packages/go/email-api/redis"
"gitea.siteworxpro.com/golang-packages/email-api-client/redis"
"net/http"
"time"
)