request

package
v0.0.0-...-6aaa5b3 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package request contains functionality related to contexts and requests.

Index

Constants

View Source
const (
	StatusActive       = "active"
	StatusInactive     = "inactive"
	StatusUpdating     = "updating"
	StatusNew          = "new"
	StatusError        = "error"
	StatusPending      = "pending"
	StatusCanceled     = "canceled"
	StatusRemove       = "remove"
	StatusRemoving     = "removing"
	StatusModified     = "modified"
	StatusBusy         = "busy"
	StatusAlerting     = "alerting"
	StatusRecovered    = "recovered"
	StatusRunning      = "running"
	StatusStopped      = "stopped"
	StatusStopping     = "stopping"
	StatusFailed       = "failed"
	StatusSuccess      = "success"
	StatusMaintenance  = "maintenance"
	StatusActivating   = "activating"
	StatusDeactivating = "deactivating"
	StatusDisconnected = "disconnected"
	StatusImporting    = "importing"
)

Valid status field values.

View Source
const (
	DefaultAccount = "default"
	SystemAccount  = "sys"
	SystemUser     = "sys"
)

Valid system entities.

View Source
const (
	ScopeSuperuser    = "superuser"
	ScopeAccountRead  = "account:read"
	ScopeAccountWrite = "account:write"
	ScopeAccountAdmin = "account:admin"
	ScopeUserRead     = "user:read"
	ScopeUserWrite    = "user:write"
	ScopeUserAdmin    = "user:admin"
	ScopeGamesRead    = "games:read"
	ScopeGamesWrite   = "games:write"
	ScopeGamesAdmin   = "games:admin"
)

Valid scopes.

Variables

Scopes is a slice of all valid scopes.

Functions

func ContextAccountID

func ContextAccountID(ctx context.Context) (string, error)

ContextAccountID extracts the account id from the context.

func ContextHasScope

func ContextHasScope(ctx context.Context, scope string) bool

ContextHasScope tests whether the context contains a specified authorization scope.

func ContextJWT

func ContextJWT(ctx context.Context) (string, error)

ContextJWT extracts the authentication token from the context.

func ContextNoCache

func ContextNoCache(ctx context.Context) (bool, error)

ContextNoCache extracts the no cache flag from the context.

func ContextRemote

func ContextRemote(ctx context.Context) (string, error)

ContextRemote extracts the remote address from the context.

func ContextReplaceTimeout

func ContextReplaceTimeout(ctx context.Context,
	d time.Duration,
) (context.Context, context.CancelFunc)

ContextReplaceTimeout creates a copy of an existing context but with a new timeout.

func ContextRequestBody

func ContextRequestBody(ctx context.Context) (string, error)

ContextRequestBody retrieves the current request body from the context.

func ContextRequestURL

func ContextRequestURL(ctx context.Context) (*url.URL, error)

ContextRequestURL retrieves the current request URL from the context.

func ContextScopes

func ContextScopes(ctx context.Context) (string, error)

ContextScopes extracts the authorization scopes from the context.

func ContextService

func ContextService(ctx context.Context) (string, error)

ContextService extracts the service name from the context.

func ContextTraceID

func ContextTraceID(ctx context.Context) (string, error)

ContextTraceID extracts the trace id from the context.

func ContextUserID

func ContextUserID(ctx context.Context) (string, error)

ContextUserID extracts the user id from the context.

func SetField

func SetField(doc *bson.D, name string, field any)

SetField adds the name and value for a field to the provided set document.

func ValidAccountID

func ValidAccountID(id string) bool

ValidAccountID checks whether a string is a valid account ID.

func ValidAccountName

func ValidAccountName(name string) bool

ValidAccountName checks whether a string is a valid account name.

func ValidGameID

func ValidGameID(id string) bool

ValidGameID checks whether a string is a valid external game ID.

func ValidScope

func ValidScope(scope string) bool

ValidScope checks whether a string is a valid scope.

func ValidScopes

func ValidScopes(scopes string) bool

ValidScopes checks whether a string is a valid scope.

func ValidUserID

func ValidUserID(id string) bool

ValidUserID checks whether a string is a valid user ID.

Types

type ContextKey

type ContextKey int

ContextKey values are used to index context data.

const (
	// CtxKeyService is used to select the service name from a context.
	CtxKeyService ContextKey = iota

	// CtxKeyRequestURL is used to select the request URL from a context.
	CtxKeyRequestURL

	// CtxKeyRequestBody is used to select the request body from a context.
	CtxKeyRequestBody

	// CtxKeyTraceID is used to select the trace ID from a context.
	CtxKeyTraceID

	// CtxKeySpanID is used to select the tracing span ID from a context.
	CtxKeySpanID

	// CtxKeyRemote is used to select a remote address from a context.
	CtxKeyRemote

	// CtxKeyNoCache is used to select the no-cache flag from a context.
	CtxKeyNoCache

	// CtxKeyJWT is used to select the authentication token from a context.
	CtxKeyJWT

	// CtxKeyScopes is used to select the authorization scopes from a context.
	CtxKeyScopes

	// CtxKeyAccountID is used to select the account id from a context.
	CtxKeyAccountID

	// CtxKeyUserID is used to select the user id from a context.
	CtxKeyUserID
)

type FieldBool

type FieldBool struct {
	Set   bool
	Valid bool
	Value bool
}

FieldBool values represent booleans tolerant of JSON inputs.

func (*FieldBool) MarshalBSON

func (f *FieldBool) MarshalBSON() ([]byte, error)

MarshalBSON encodes this value into a BSON format byte slice.

func (*FieldBool) MarshalJSON

func (f *FieldBool) MarshalJSON() ([]byte, error)

MarshalJSON encodes this value into a JSON format byte slice.

func (FieldBool) MarshalYAML

func (f FieldBool) MarshalYAML() (any, error)

MarshalYAML encodes a this value into a YAML format byte slice.

func (*FieldBool) Scan

func (f *FieldBool) Scan(src any) error

Scan allows this value to be used in database/sql scan functions.

func (*FieldBool) String

func (f *FieldBool) String() string

String returns the value as a string.

func (*FieldBool) UnmarshalBSON

func (f *FieldBool) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes a BSON format byte slice into this value.

func (*FieldBool) UnmarshalJSON

func (f *FieldBool) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON format byte slice into this value.

func (*FieldBool) UnmarshalYAML

func (f *FieldBool) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML format byte slice into this value.

type FieldDuration

type FieldDuration struct {
	Set   bool
	Valid bool
	Value time.Duration
}

FieldDuration values represent integers tolerant of JSON inputs.

func (*FieldDuration) MarshalBSON

func (f *FieldDuration) MarshalBSON() ([]byte, error)

MarshalBSON encodes this value into a BSON format byte slice.

func (*FieldDuration) MarshalJSON

func (f *FieldDuration) MarshalJSON() ([]byte, error)

MarshalJSON encodes this value into a JSON format byte slice.

func (FieldDuration) MarshalYAML

func (f FieldDuration) MarshalYAML() (any, error)

MarshalYAML encodes a this value into a YAML format byte slice.

func (*FieldDuration) Scan

func (f *FieldDuration) Scan(src any) error

Scan allows this value to be used in database/sql scan functions.

func (*FieldDuration) String

func (f *FieldDuration) String() string

String returns the value as a string.

func (*FieldDuration) UnmarshalBSON

func (f *FieldDuration) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes a BSON format byte slice into this value.

func (*FieldDuration) UnmarshalJSON

func (f *FieldDuration) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON format byte slice into this value.

func (*FieldDuration) UnmarshalYAML

func (f *FieldDuration) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML format byte slice into this value.

type FieldFloat64

type FieldFloat64 struct {
	Set   bool
	Valid bool
	Value float64
}

FieldFloat64 values represent floats tolerant of JSON inputs.

func (*FieldFloat64) MarshalBSON

func (f *FieldFloat64) MarshalBSON() ([]byte, error)

MarshalBSON encodes this value into a BSON format byte slice.

func (*FieldFloat64) MarshalJSON

func (f *FieldFloat64) MarshalJSON() ([]byte, error)

MarshalJSON encodes this value into a JSON format byte slice.

func (FieldFloat64) MarshalYAML

func (f FieldFloat64) MarshalYAML() (any, error)

MarshalYAML encodes a this value into a YAML format byte slice.

func (*FieldFloat64) Scan

func (f *FieldFloat64) Scan(src any) error

Scan allows this value to be used in database/sql scan functions.

func (*FieldFloat64) String

func (f *FieldFloat64) String() string

String returns the value as a string.

func (*FieldFloat64) UnmarshalBSON

func (f *FieldFloat64) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes a BSON format byte slice into this value.

func (*FieldFloat64) UnmarshalJSON

func (f *FieldFloat64) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON format byte slice into this value.

func (*FieldFloat64) UnmarshalYAML

func (f *FieldFloat64) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML format byte slice into this value.

type FieldInt64

type FieldInt64 struct {
	Set   bool
	Valid bool
	Value int64
}

FieldInt64 values represent integers tolerant of JSON inputs.

func (*FieldInt64) MarshalBSON

func (f *FieldInt64) MarshalBSON() ([]byte, error)

MarshalBSON encodes this value into a BSON format byte slice.

func (*FieldInt64) MarshalJSON

func (f *FieldInt64) MarshalJSON() ([]byte, error)

MarshalJSON encodes this value into a JSON format byte slice.

func (FieldInt64) MarshalYAML

func (f FieldInt64) MarshalYAML() (any, error)

MarshalYAML encodes a this value into a YAML format byte slice.

func (*FieldInt64) Scan

func (f *FieldInt64) Scan(src any) error

Scan allows this value to be used in database/sql scan functions.

func (*FieldInt64) String

func (f *FieldInt64) String() string

String returns the value as a string.

func (*FieldInt64) UnmarshalBSON

func (f *FieldInt64) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes a BSON format byte slice into this value.

func (*FieldInt64) UnmarshalJSON

func (f *FieldInt64) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON format byte slice into this value.

func (*FieldInt64) UnmarshalYAML

func (f *FieldInt64) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML format byte slice into this value.

type FieldInt64Array

type FieldInt64Array struct {
	Set   bool
	Valid bool
	Value []int64
}

FieldInt64Array values represent string arrays tolerant of JSON inputs.

func (*FieldInt64Array) MarshalBSON

func (f *FieldInt64Array) MarshalBSON() ([]byte, error)

MarshalBSON encodes this value into a BSON format byte slice.

func (*FieldInt64Array) MarshalJSON

func (f *FieldInt64Array) MarshalJSON() ([]byte, error)

MarshalJSON encodes this value into a JSON format byte slice.

func (FieldInt64Array) MarshalYAML

func (f FieldInt64Array) MarshalYAML() (any, error)

MarshalYAML encodes a this value into a YAML format byte slice.

func (*FieldInt64Array) String

func (f *FieldInt64Array) String() string

String returns the value as a string.

func (*FieldInt64Array) UnmarshalBSON

func (f *FieldInt64Array) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes a BSON format byte slice into this value.

func (*FieldInt64Array) UnmarshalJSON

func (f *FieldInt64Array) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON format byte slice into this value.

func (*FieldInt64Array) UnmarshalYAML

func (f *FieldInt64Array) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML format byte slice into this value.

type FieldJSON

type FieldJSON struct {
	Set   bool
	Valid bool
	Value map[string]any
}

FieldJSON values represent unparsed JSON objects.

func (FieldJSON) Copy

func (f FieldJSON) Copy() FieldJSON

Copy creates a copy of this value.

func (*FieldJSON) MarshalBSON

func (f *FieldJSON) MarshalBSON() ([]byte, error)

MarshalBSON encodes this value into a BSON format byte slice.

func (*FieldJSON) MarshalJSON

func (f *FieldJSON) MarshalJSON() ([]byte, error)

MarshalJSON encodes this value into a JSON format byte slice.

func (FieldJSON) MarshalYAML

func (f FieldJSON) MarshalYAML() (any, error)

MarshalYAML encodes a this value into a YAML format byte slice.

func (*FieldJSON) Scan

func (f *FieldJSON) Scan(src any) error

Scan allows this value to be used in database/sql scan functions.

func (*FieldJSON) String

func (f *FieldJSON) String() string

String returns the value as a string.

func (*FieldJSON) UnmarshalBSON

func (f *FieldJSON) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes a BSON format byte slice into this value.

func (*FieldJSON) UnmarshalJSON

func (f *FieldJSON) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON format byte slice into this value.

func (*FieldJSON) UnmarshalYAML

func (f *FieldJSON) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML format byte slice into this value.

type FieldString

type FieldString struct {
	Set   bool
	Valid bool
	Value string
}

FieldString values represent strings tolerant of JSON inputs.

func (*FieldString) MarshalBSON

func (f *FieldString) MarshalBSON() ([]byte, error)

MarshalBSON encodes this value into a BSON format byte slice.

func (*FieldString) MarshalJSON

func (f *FieldString) MarshalJSON() ([]byte, error)

MarshalJSON encodes this value into a JSON format byte slice.

func (FieldString) MarshalYAML

func (f FieldString) MarshalYAML() (any, error)

MarshalYAML encodes a this value into a YAML format byte slice.

func (*FieldString) Scan

func (f *FieldString) Scan(src any) error

Scan allows this value to be used in database/sql scan functions.

func (*FieldString) String

func (f *FieldString) String() string

String returns the value as a string.

func (*FieldString) UnmarshalBSON

func (f *FieldString) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes a BSON format byte slice into this value.

func (*FieldString) UnmarshalJSON

func (f *FieldString) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON format byte slice into this value.

func (*FieldString) UnmarshalYAML

func (f *FieldString) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML format byte slice into this value.

type FieldStringArray

type FieldStringArray struct {
	Set   bool
	Valid bool
	Value []string
}

FieldStringArray values represent string arrays tolerant of JSON inputs.

func (*FieldStringArray) MarshalBSON

func (f *FieldStringArray) MarshalBSON() ([]byte, error)

MarshalBSON encodes this value into a BSON format byte slice.

func (*FieldStringArray) MarshalJSON

func (f *FieldStringArray) MarshalJSON() ([]byte, error)

MarshalJSON encodes this value into a JSON format byte slice.

func (FieldStringArray) MarshalYAML

func (f FieldStringArray) MarshalYAML() (any, error)

MarshalYAML encodes a this value into a YAML format byte slice.

func (*FieldStringArray) String

func (f *FieldStringArray) String() string

String returns the value as a string.

func (*FieldStringArray) UnmarshalBSON

func (f *FieldStringArray) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes a BSON format byte slice into this value.

func (*FieldStringArray) UnmarshalJSON

func (f *FieldStringArray) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON format byte slice into this value.

func (*FieldStringArray) UnmarshalYAML

func (f *FieldStringArray) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML format byte slice into this value.

type FieldTime

type FieldTime struct {
	Set   bool
	Valid bool
	Value int64
}

FieldTime values represent timestamps tolerant of JSON inputs.

func (*FieldTime) MarshalBSON

func (f *FieldTime) MarshalBSON() ([]byte, error)

MarshalBSON encodes this value into a BSON format byte slice.

func (*FieldTime) MarshalJSON

func (f *FieldTime) MarshalJSON() ([]byte, error)

MarshalJSON encodes this value into a JSON format byte slice.

func (FieldTime) MarshalYAML

func (f FieldTime) MarshalYAML() (any, error)

MarshalYAML encodes a this value into a YAML format byte slice.

func (*FieldTime) Scan

func (f *FieldTime) Scan(src any) error

Scan allows this value to be used in database/sql scan functions.

func (*FieldTime) String

func (f *FieldTime) String() string

String returns the value as a string.

func (*FieldTime) UnmarshalBSON

func (f *FieldTime) UnmarshalBSON(b []byte) error

UnmarshalBSON decodes a BSON format byte slice into this value.

func (*FieldTime) UnmarshalJSON

func (f *FieldTime) UnmarshalJSON(b []byte) error

UnmarshalJSON decodes a JSON format byte slice into this value.

func (*FieldTime) UnmarshalYAML

func (f *FieldTime) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML decodes a YAML format byte slice into this value.

type Query

type Query struct {
	Search string `json:"search,omitempty"`
	Size   int64  `json:"size,omitempty"`
	Skip   int64  `json:"skip,omitempty"`
	Sort   string `json:"sort,omitempty"`
}

Query messages represent query string search requests.

func NewQuery

func NewQuery() *Query

func ParseQuery

func ParseQuery(values url.Values) (*Query, error)

ParseQuery parses a string in query string format into a Query value that can be used for search functions.

Jump to

Keyboard shortcuts

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