You've already forked email-api-client
refactor: update package paths and improve client context handling
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 22s
All checks were successful
🚀 Publish Release Package / publish (push) Successful in 22s
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"git.s.int/packages/go/utilities/Env"
|
||||
"gitea.siteworxpro.com/golang-packages/utilities/Env"
|
||||
"log"
|
||||
)
|
||||
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user