internal

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

DefaultLanguage is the default language applied by default.

View Source
var HTTPClient contextKey

HTTPClient is the context key used to specify the HTTP client used to issue the request.

Functions

func Apply

func Apply(req *http.Request, opts []RequestOption) error

Apply applies the given RequestOptions to the request in order. Caller-provided opts take precedence over any defaults appended after them. For example, append caller opts before defaults like append(opts, internal.DefaultLanguage) so that the caller's preferences are evaluated first.

func ContextClient

func ContextClient(ctx context.Context) *http.Client

ContextClient returns an HTTP client based on the given context.Context.

func Post

func Post[T any](ctx context.Context, client *http.Client, u *url.URL, reqBody any, opts []RequestOption) (value T, err error)

Post issues a POST request to the endpoint.

Types

type Error

type Error struct {
	// StatusCode is the HTTP status code of the response, e.g. 404.
	StatusCode int `json:"code,omitempty"`
	// Type indicates the type of the Error.
	Type string `json:"error,omitempty"`
	// Code is the numerical error code for the Error.
	Code int `json:"errorCode,omitempty"`
	// Details encapsulates custom data specific to the Error.
	Details map[string][]string `json:"errorDetails,omitempty"`
	// Message optionally contains a human-readable message describing the Error.
	Message string `json:"errorMessage,omitempty"`
	// Status is the HTTP status of the response, e.g. Not Found.
	Status string `json:"status,omitempty"`
}

Error represents an error included in the response body.

func (Error) Error

func (err Error) Error() string

Error returns a string representation of the Error.

type RequestOption

type RequestOption func(req *http.Request) error

RequestOption specifies an option to be applied to an outgoing HTTP request.

Callers may accept multiple RequestOptions as a variadic or slice parameter. Options must be applied to the request using Apply.

A RequestOption must be reusable and must not hold any per-request state.

func AcceptLanguage

func AcceptLanguage(tags []language.Tag) RequestOption

AcceptLanguage returns a internal.RequestOption that appends the given language tags to the 'Accept-Language' header on outgoing requests, preserving any tags already present in the header.

func RequestHeader

func RequestHeader(key, value string) RequestOption

RequestHeader returns a internal.RequestOption that sets a request header with the given name and value on outgoing requests.

type Result

type Result[T any] struct {
	// StatusCode is the HTTP status code of the response, e.g. 200.
	StatusCode int `json:"code,omitempty"`
	// Data is the payload of the Result.
	Data T `json:"data,omitempty"`
	// Status is the HTTP status of the response, e.g. OK.
	Status string `json:"status,omitempty"`
}

Result represents a successful response in PlayFab API. Make sure to specify the T generic type to whatever you want in the Data.

Jump to

Keyboard shortcuts

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