api

package
v0.19.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2026 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
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()
client.SetEndpoint("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() *GraphQLClient

NewGraphQLClient returns a new GraphQLClient with no endpoint set. Call SetEndpoint before issuing queries. 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) SetEndpoint added in v0.19.8

func (g *GraphQLClient) SetEndpoint(endpoint string) *GraphQLClient

SetEndpoint configure endpoint 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 MapRoute added in v0.16.6

type MapRoute struct {
	Flag    bool   `json:"flag"`
	MockURL string `json:"mock_url"`
}

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.

func (*SOAPFault) Error added in v0.19.3

func (f *SOAPFault) Error() string

Error implements the error interface.

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 SurroundingLogRequest struct {
	Method string `json:"method"`
	Header any    `json:"header"`
	Body   any    `json:"body"`
}

type SurroundingLogResponse added in v0.16.6

type SurroundingLogResponse struct {
	HttpCode int `json:"http_code"`
	Header   any `json:"header"`
	Body     any `json:"body"`
}

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL