Documentation
¶
Index ¶
- Variables
- func ToObject[T any](obj HTTPResponse) (T, error)
- type ClientExternalSurroundingLog
- type GraphQLBody
- type GraphQLClient
- func (g *GraphQLClient) Query(ctx context.Context, query string, variables map[string]any, ...) (HTTPResponse, error)
- func (g *GraphQLClient) SetBasicAuth(username, password string) *GraphQLClient
- func (g *GraphQLClient) SetBearerToken(token string) *GraphQLClient
- func (g *GraphQLClient) SetHeaders(headers map[string]string) *GraphQLClient
- type GraphQLLogDetail
- type GraphQLSurroundingLog
- type HTTPClient
- type HTTPClientExternal
- type HTTPResponse
- type MapRoute
- type SOAPClient
- type SOAPFault
- type SOAPOption
- type SOAPSurroundingLog
- type SOAPVersion
- type SurroundingLogRequest
- type SurroundingLogResponse
- type WSPasswordType
- type WSSecurity
Constants ¶
This section is empty.
Variables ¶
var DEFAULT_TIMEOUT = 10 * time.Second
DEFAULT_TIMEOUT the default timeout of team specification.
Functions ¶
func ToObject ¶
func ToObject[T any](obj HTTPResponse) (T, error)
ToObject transform HTTPResponse.GetBody to any object using json encoding.
Types ¶
type ClientExternalSurroundingLog ¶ added in v0.16.6
type ClientExternalSurroundingLog struct {
AppName string `json:"app_name"`
Path string `json:"path"`
Host string `json:"host"`
Url string `json:"url"`
Request SurroundingLogRequest `json:"request"`
Response SurroundingLogResponse `json:"response"`
ResponseTime time.Duration `json:"response_time"`
MemoryUsage uint64 `json:"memory_usage"`
}
type GraphQLBody ¶ added in v0.19.6
type GraphQLBody struct {
Query string `json:"query"`
Variables map[string]any `json:"variables,omitempty"`
OperationName *string `json:"operationName,omitempty"`
}
GraphQLBody is the JSON body sent with every GraphQL request.
type GraphQLClient ¶ added in v0.19.6
type GraphQLClient struct {
// contains filtered or unexported fields
}
GraphQLClient is a thin, 1:1 Go equivalent of the PHP GraphQLClient library. It always posts to a fixed endpoint and supports basic auth, bearer token, and arbitrary extra headers.
Usage:
client := api.NewGraphQLClient("https://api.example.com/graphql")
client.SetBearerToken("my-jwt")
resp, err := client.Query(ctx, `{ users { id } }`, nil, nil)
func NewGraphQLClient ¶ added in v0.19.6
func NewGraphQLClient(endpoint string) *GraphQLClient
NewGraphQLClient returns a new GraphQLClient targeting endpoint. Default timeout is 10 s, TLS verification is skipped (matching the PHP default).
func (*GraphQLClient) Query ¶ added in v0.19.6
func (g *GraphQLClient) Query( ctx context.Context, query string, variables map[string]any, operationName *string, ) (HTTPResponse, error)
Query executes a GraphQL query/mutation against the configured endpoint. variables and operationName are optional (pass nil to omit them). The surrounding log is written when APP_DEBUG is "true".
func (*GraphQLClient) SetBasicAuth ¶ added in v0.19.6
func (g *GraphQLClient) SetBasicAuth(username, password string) *GraphQLClient
SetBasicAuth configures HTTP Basic authentication for every request. Returns the receiver so calls can be chained.
func (*GraphQLClient) SetBearerToken ¶ added in v0.19.6
func (g *GraphQLClient) SetBearerToken(token string) *GraphQLClient
SetBearerToken sets the Authorization header to "Bearer <token>". Returns the receiver so calls can be chained.
func (*GraphQLClient) SetHeaders ¶ added in v0.19.6
func (g *GraphQLClient) SetHeaders(headers map[string]string) *GraphQLClient
SetHeaders merges the supplied headers into the client's default header set. Duplicate keys will be overwritten by the supplied values. Returns the receiver so calls can be chained.
type GraphQLLogDetail ¶ added in v0.19.6
type GraphQLLogDetail struct {
Query string `json:"query"`
Variables map[string]any `json:"variables,omitempty"`
OperationName *string `json:"operationName,omitempty"`
}
GraphQLLogDetail captures the GQL-specific parts of the request for the log.
type GraphQLSurroundingLog ¶ added in v0.19.6
type GraphQLSurroundingLog struct {
Host string `json:"host"`
Url string `json:"url"`
GraphQL GraphQLLogDetail `json:"graphql"`
Request SurroundingLogRequest `json:"request"`
Response SurroundingLogResponse `json:"response"`
ResponseTime time.Duration `json:"response_time"`
MemoryUsage uint64 `json:"memory_usage"`
}
GraphQLSurroundingLog holds the surrounding-log payload for a GraphQL call.
type HTTPClient ¶ added in v0.16.0
type HTTPClient interface {
// Call send given request using HTTP, and optionally set custom timeout if
// provided, otherwise will use DEFAULT_TIMEOUT.
//
// This function also help setting any necessary metadata for spotlibs using
// ctx pkg that also come from this lib.
Call(req *http.Request, timeouts ...time.Duration) (HTTPResponse, error)
}
func NewHTTPClient ¶ added in v0.16.0
func NewHTTPClient() HTTPClient
NewHTTPClient return HTTPClient implementer that also set some metadata header before sending the request.
type HTTPClientExternal ¶ added in v0.16.6
type HTTPClientExternal interface {
// Call send given request using HTTP, and optionally set custom timeout if
// provided, otherwise will use DEFAULT_TIMEOUT.
//
// This function also help setting any necessary metadata for spotlibs using
// ctx pkg that also come from this lib.
Call(requestClient context.Context, req *http.Request, timeouts ...time.Duration) (HTTPResponse, error)
}
func NewHTTPClientExternal ¶ added in v0.16.6
func NewHTTPClientExternal() HTTPClientExternal
NewHTTPClientExternal return HTTPClient implementer that also set some metadata header before sending the request.
type HTTPResponse ¶ added in v0.16.0
type HTTPResponse interface {
// GetStatusCode get the http status code.
GetStatusCode() int
// GetBody get the raw response body in bytes.
GetBody() []byte
// GetHeaders get the original response header, after combining the value to
// one using comma.
GetHeaders() map[string]string
// GetHeader get the response header by the given key after combining the value
// using comma.
GetHeader(key string) string
}
type SOAPClient ¶ added in v0.19.3
type SOAPClient interface {
// Call sends a SOAP request to the given URL with the specified action
// and parameters. Returns the raw content of <{Action}Result> element
// (typically a JSON string for .NET services).
//
// The caller is responsible for unmarshaling the result bytes.
Call(ctx context.Context, url string, action string, params map[string]string, timeouts ...time.Duration) ([]byte, error)
}
SOAPClient is the interface for making SOAP calls.
func NewSOAPClient ¶ added in v0.19.3
func NewSOAPClient(opts ...SOAPOption) SOAPClient
NewSOAPClient creates a new SOAP client with the given options.
type SOAPFault ¶ added in v0.19.3
type SOAPFault struct {
Code string // e.g. "soap:Server" (1.1) or "env:Sender" (1.2)
Reason string // human-readable error message
Detail string // optional detail content
}
SOAPFault represents a parsed SOAP fault from either version.
type SOAPOption ¶ added in v0.19.3
type SOAPOption func(*soapClient)
SOAPOption is a functional option for configuring SOAPClient.
func WithSOAPVersion ¶ added in v0.19.3
func WithSOAPVersion(v SOAPVersion) SOAPOption
WithSOAPVersion sets the SOAP protocol version. Default is SOAP11.
func WithTargetNamespace ¶ added in v0.19.3
func WithTargetNamespace(ns string) SOAPOption
WithTargetNamespace sets the target namespace for SOAP actions. Default is "http://tempuri.org/".
func WithWSSecurity ¶ added in v0.19.3
func WithWSSecurity(ws WSSecurity) SOAPOption
WithWSSecurity enables WS-Security with the given configuration.
type SOAPSurroundingLog ¶ added in v0.19.3
type SOAPSurroundingLog struct {
AppName string `json:"app_name"`
Path string `json:"path"`
Host string `json:"host"`
URL string `json:"url"`
SOAPAction string `json:"soap_action"`
SOAPVersion string `json:"soap_version"`
Request SurroundingLogRequest `json:"request"`
Response SurroundingLogResponse `json:"response"`
ResponseTime time.Duration `json:"response_time"`
MemoryUsage uint64 `json:"memory_usage"`
}
SOAPSurroundingLog holds the data for surrounding log of SOAP calls.
type SOAPVersion ¶ added in v0.19.3
type SOAPVersion int
SOAPVersion represents the SOAP protocol version.
const ( // SOAP11 uses namespace http://schemas.xmlsoap.org/soap/envelope/ // Content-Type: text/xml; charset=utf-8 // Action via SOAPAction header. SOAP11 SOAPVersion = iota // SOAP12 uses namespace http://www.w3.org/2003/05/soap-envelope // Content-Type: application/soap+xml; charset=utf-8; action="..." // Action embedded in Content-Type. SOAP12 )
type SurroundingLogRequest ¶ added in v0.16.6
type SurroundingLogResponse ¶ added in v0.16.6
type WSPasswordType ¶ added in v0.19.3
type WSPasswordType int
WSPasswordType represents the password encoding type for WS-Security.
const ( // WSPasswordPlainText sends password as plain text. WSPasswordPlainText WSPasswordType = iota // WSPasswordDigest sends password as Base64(SHA1(Nonce + Created + Password)). WSPasswordDigest )
type WSSecurity ¶ added in v0.19.3
type WSSecurity struct {
Username string
Password string
PasswordType WSPasswordType
AddTimestamp bool // Add wsu:Timestamp to Security header
AddNonce bool // Add Nonce to UsernameToken (always true for Digest)
TimestampTTL time.Duration // Timestamp validity duration (default: 5 minutes)
}
WSSecurity holds the configuration for WS-Security UsernameToken.