schema

package
v0.0.0-...-43af894 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package schema represents the tree structure of an API schema.

For more information, refer to the main "steamweb" package documentation.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmptyInterfaces is returned when trying to manipulate an empty `Interfaces`.
	ErrEmptyInterfaces = errors.New("empty interfaces collection")
	// ErrMixedInterfaces is returned when trying to use group helpers on a `Interfaces` collection
	// containing mixed interface names.
	ErrMixedInterfaces = errors.New("mixed interfaces collection")
	// ErrMixedMethods is returned when trying to use group helpers on a `Methods` collection
	// containing mixed method names.
	ErrMixedMethods = errors.New("mixed methods collection")
)

Functions

This section is empty.

Types

type Interface

type Interface struct {
	Name    string  `json:"name"`
	Methods Methods `json:"methods"`
	// contains filtered or unexported fields
}

Interface holds the specification of an API interface.

func MustNewInterface

func MustNewInterface(name string, methods Methods) *Interface

MustNewInterface is like `NewInterface` but panics on errors.

func NewInterface

func NewInterface(name string, methods Methods) (*Interface, error)

NewInterface creates a new `Interface`.

Returns `Interface.Validate` errors.

func (*Interface) Key

func (si *Interface) Key() *InterfaceKey

Key returns the key identifying the interface.

It panics if key was not parsed (`Interface` was created without `NewInterface` and `Validate` was not called).

func (*Interface) Validate

func (si *Interface) Validate() error

Validate checks if fields are valid.

It should be used after creating or updating an `Interface` (unmarshalling or direct instantiation without `NewInterface`).

Returns `*InvalidInterfaceError` on error, wrapping one of the errors:

  • `*InvalidInterfaceNameError` if the interface has an invalid name.
  • `*InvalidMethodError` if any of the interface methods are invalid.

type InterfaceGroupsByName

type InterfaceGroupsByName map[string]InterfacesIndex

InterfaceGroupsByName groups `Interface`s with the same base name.

The definition of base name is described in `InterfaceKey`.

It's a regular map and therefore provides no guarantees on consistency:

  • Keys are not guaranteed to be correctly associated to their respective interfaces
  • Interfaces are not guaranteed to be unique for each key
  • Interfaces are not guaranteed to have the same base name

The group creator is responsible for ensuring consistency. Groups created with `NewInterfaceGroupsByName` or `Interfaces.GroupByName` can be considered consistent.

Behavior of inconsistent groups is undefined.

func NewInterfaceGroupsByName

func NewInterfaceGroupsByName(interfaces Interfaces) InterfaceGroupsByName

NewInterfaceGroupsByName groups interfaces as described in `InterfaceGroupsByName`.

type InterfaceKey

type InterfaceKey struct {
	Name  string
	AppID steamlib.AppID
}

InterfaceKey is the key that uniquely identifies a `Interface`.

Interface names are formed by a base name and an optional AppID part, in the format `<BaseName>_<AppID>`. Interfaces can be non app-specific and omit the "_<AppID>" part, in these cases Key returns a key with AppID = 0.

For example in "IDOTAMatch_570", the base name is "IDOTAMatch" and AppID is 570. In "ISteamApps", the base name is "ISteamApps" and AppID is 0.

func (*InterfaceKey) String

func (k *InterfaceKey) String() string

String formats the key.

type InterfaceNotFoundError

type InterfaceNotFoundError struct {
	Key *InterfaceKey
}

InterfaceNotFoundError is returned when tried to access an interface with invalid name or invalid AppID.

func (*InterfaceNotFoundError) Error

func (err *InterfaceNotFoundError) Error() string

Error implements interface `error`.

type Interfaces

type Interfaces []*Interface

Interfaces is a collection of `Interface`s.

func MustNewInterfaces

func MustNewInterfaces(interfaces ...*Interface) Interfaces

MustNewInterfaces is like `NewInterfaces` but panics if it returned an error.

func NewInterfaces

func NewInterfaces(interfaces ...*Interface) (Interfaces, error)

NewInterfaces creates a new `Interface` collection.

Returns `Interfaces.Validate` errors.

func (Interfaces) Get

func (c Interfaces) Get(key *InterfaceKey) (*Interface, error)

Get returns the interface with given key.

Returns error `*InterfaceNotFoundError` if none was found.

func (Interfaces) GroupByBaseName

func (c Interfaces) GroupByBaseName() InterfaceGroupsByName

GroupByBaseName groups the interfaces by base name.

The definition of base name is described in `InterfaceKey`.

func (Interfaces) Validate

func (c Interfaces) Validate() error

Validate checks whether all interfaces in the collection are valid.

Returns `Interface.Validate` errors.

type InterfacesIndex

type InterfacesIndex map[InterfaceKey]*Interface

InterfacesIndex is an index of `Interface`s keyed by `InterfaceKey`.

func NewInterfacesIndex

func NewInterfacesIndex(interfaces Interfaces) InterfacesIndex

NewInterfacesIndex creates an `InterfacesIndex`.

func (InterfacesIndex) AppIDs

func (i InterfacesIndex) AppIDs() []steamlib.AppID

AppIDs collects the AppID of all interfaces in the index.

Interfaces with no AppID (0) are omitted.

func (InterfacesIndex) GroupMethodsByName

func (i InterfacesIndex) GroupMethodsByName() MethodGroupsByName

GroupMethodsByName groups all methods in the index by method name.

func (InterfacesIndex) Name

func (i InterfacesIndex) Name() string

Name returns the base name of the first `Interface` in the index.

The definition of base name is described in `InterfaceKey`.

This should be used with an `InterfaceIndex` within an `InterfaceGroupsByName`.

Returns an empty string if the index is empty.

type InvalidInterfaceError

type InvalidInterfaceError struct {
	// contains filtered or unexported fields
}

InvalidInterfaceError is returned when an `Interface` is invalid.

func (*InvalidInterfaceError) Error

func (err *InvalidInterfaceError) Error() string

Error implements interface `error`.

func (*InvalidInterfaceError) Unwrap

func (err *InvalidInterfaceError) Unwrap() error

Unwrap implements `errors.Unwrap`.

type InvalidInterfaceNameError

type InvalidInterfaceNameError struct {
	Name string
	// contains filtered or unexported fields
}

InvalidInterfaceNameError is returned when an interface has an invalid name.

func (*InvalidInterfaceNameError) Error

func (err *InvalidInterfaceNameError) Error() string

Error implements interface `error`.

func (*InvalidInterfaceNameError) Unwrap

func (err *InvalidInterfaceNameError) Unwrap() error

Unwrap implements `errors.Unwrap`.

type InvalidMethodError

type InvalidMethodError struct {
	// contains filtered or unexported fields
}

InvalidMethodError is returned when a `Method` is invalid.

func (*InvalidMethodError) Error

func (err *InvalidMethodError) Error() string

Error implements interface `error`.

func (*InvalidMethodError) Unwrap

func (err *InvalidMethodError) Unwrap() error

Unwrap implements `errors.Unwrap`.

type InvalidMethodHTTPMethodError

type InvalidMethodHTTPMethodError struct {
	Name       string
	Version    int
	HTTPMethod string
}

InvalidMethodHTTPMethodError is returned when a method has an invalid version.

func NewInvalidMethodHTTPMethodError

func NewInvalidMethodHTTPMethodError(sm *Method) *InvalidMethodHTTPMethodError

func (*InvalidMethodHTTPMethodError) Error

func (err *InvalidMethodHTTPMethodError) Error() string

Error implements interface `error`.

type InvalidMethodNameError

type InvalidMethodNameError struct {
	Name    string
	Version int
}

InvalidMethodNameError is returned when a method has an invalid name.

func NewInvalidMethodNameError

func NewInvalidMethodNameError(sm *Method) *InvalidMethodNameError

func (*InvalidMethodNameError) Error

func (err *InvalidMethodNameError) Error() string

Error implements interface `error`.

type InvalidMethodVersionError

type InvalidMethodVersionError struct {
	Name    string
	Version int
}

InvalidMethodVersionError is returned when a method has an invalid version.

func NewInvalidMethodVersionError

func NewInvalidMethodVersionError(sm *Method) *InvalidMethodVersionError

func (*InvalidMethodVersionError) Error

func (err *InvalidMethodVersionError) Error() string

Error implements interface `error`.

type InvalidSchemaError

type InvalidSchemaError struct {
	// contains filtered or unexported fields
}

InvalidSchemaError is returned when a `Schema` is invalid.

func (*InvalidSchemaError) Error

func (err *InvalidSchemaError) Error() string

Error implements interface `error`.

func (*InvalidSchemaError) Unwrap

func (err *InvalidSchemaError) Unwrap() error

Unwrap implements `errors.Unwrap`.

type Method

type Method struct {
	Name         string       `json:"name"`
	Version      int          `json:"version"`
	HTTPMethod   string       `json:"httpmethod"`
	Params       MethodParams `json:"parameters"`
	Undocumented bool         `json:"undocumented"`
	// contains filtered or unexported fields
}

Method holds the specification of an API interface method.

func MustNewMethod

func MustNewMethod(
	name string,
	version int,
	httpMethod string,
	params MethodParams,
	undocumented bool,
) *Method

func NewMethod

func NewMethod(
	name string,
	version int,
	httpMethod string,
	params MethodParams,
	undocumented bool,
) (*Method, error)

NewMethod creates a new interface `Method`.

Returns `Method.Validate` errors.

func (*Method) FormatVersion

func (m *Method) FormatVersion() string

FormatVersion returns the formatted version string (in the format "v<version>") to be used as a request path parameter.

func (*Method) Key

func (m *Method) Key() *MethodKey

Key returns the key identifying the method.

func (*Method) Validate

func (sm *Method) Validate() error

Validate checks if fields are valid.

It should be used after creating or updating a Method (unmarshalling or direct instantiation without `NewMethod`).

Returns `*InvalidMethodError` on error, wrapping one of the following errors:

  • `*InvalidMethodNameError` if the method has an invalid name.
  • `*InvalidMethodVersionError` if the method has an invalid version.
  • `*InvalidMethodHTTPMethodError` if the method has an invalid http method.

func (*Method) ValidateParams

func (m *Method) ValidateParams(params url.Values) error

ValidateParams validates the given parameters against the params collection.

Returns errors described in `MethodParams.ValidateParams`.

type MethodGroupsByName

type MethodGroupsByName map[string]MethodsIndex

MethodGroupsByName groups `Method`s with the same name.

It's a regular map and therefore provides no guarantees on consistency:

  • Keys are not guaranteed to be correctly associated to their respective methods
  • Methods are not guaranteed to be unique for each key
  • Methods are not guaranteed to have the same name

The group creator is responsible for ensuring consistency. Groups created with `NewMethodsGroupByName` or `Methods.GroupByName` can be considered consistent.

Behavior of inconsistent groups is undefined.

func NewMethodGroupsByName

func NewMethodGroupsByName(methods Methods) MethodGroupsByName

NewMethodGroupsByName groups methods as described in `MethodGroupsByName`.

type MethodKey

type MethodKey struct {
	Name    string
	Version int
}

MethodKey is the key that uniquely identifies a `Method`.

func (*MethodKey) String

func (k *MethodKey) String() string

String formats the key.

type MethodNotFoundError

type MethodNotFoundError struct {
	Key *MethodKey
}

MethodNotFoundError is returned when tried to access an interface method with invalid name or invalid version.

func (*MethodNotFoundError) Error

func (err *MethodNotFoundError) Error() string

Error implements interface `error`.

type MethodParam

type MethodParam struct {
	Name        string `json:"name"`
	Type        string `json:"type"`
	Optional    bool   `json:"optional"`
	Description string `json:"description"`
}

MethodParam holds the specification of an API interface method parameter.

func NewMethodParam

func NewMethodParam(
	name string,
	ty string,
	optional bool,
	description string,
) *MethodParam

func (*MethodParam) ValidateValue

func (p *MethodParam) ValidateValue(value string) error

ValidateValue validates the given value against the parameter specification.

Returns an error of type `*RequiredParameterError` if the parameter is required and the value is empty.

type MethodParams

type MethodParams []*MethodParam

MethodParams is a collection of `MethodParam`s.

func NewMethodParams

func NewMethodParams(params ...*MethodParam) MethodParams

NewMethodParams creates a new `MethodParam` collection.

func (MethodParams) ValidateParams

func (c MethodParams) ValidateParams(params url.Values) error

ValidateParams validates the given parameters against each parameter in the collection.

Returns `MethodParam.ValidateValue` errors.

type Methods

type Methods []*Method

Methods is a collection of `Method`s.

func MustNewMethods

func MustNewMethods(methods ...*Method) Methods

MustNewMethods is like `NewMethods` but panics on errors.

func NewMethods

func NewMethods(methods ...*Method) (Methods, error)

NewMethods creates a new `Method` collection.

Returns `Methods.Validate` errors.

func (Methods) Get

func (c Methods) Get(key *MethodKey) (*Method, error)

Get returns the method with the given key.

Returns error `*InterfaceMethodNotFoundError` if none was found.

func (Methods) GroupByName

func (c Methods) GroupByName() MethodGroupsByName

GroupByName groups the methods by name.

func (Methods) Validate

func (c Methods) Validate() error

Validate checks whether all methods in the collection are valid.

Returns `Method.Validate` errors.

type MethodsIndex

type MethodsIndex map[MethodKey]*Method

MethodsIndex is an index of `Method`s keyed by `MethodKey`.

func NewMethodsIndex

func NewMethodsIndex(methods Methods) MethodsIndex

NewMethodsIndex creates a `MethodIndex`.

func (MethodsIndex) Versions

func (i MethodsIndex) Versions() []int

Versions collects the versions of all methods in the index.

type RequiredParameterError

type RequiredParameterError struct {
	Param *MethodParam
}

RequiredParameterError is returned when a required parameter is missing.

func (*RequiredParameterError) Error

func (err *RequiredParameterError) Error() string

Error implements interface `error`.

type Schema

type Schema struct {
	Interfaces Interfaces `json:"interfaces"`
}

Schema is the root of an API schema specification.

func NewSchema

func NewSchema(interfaces Interfaces) (*Schema, error)

NewSchema creates a new `Schema`.

Returns `Schema.Validate` errors.

func (*Schema) Validate

func (s *Schema) Validate() error

Validate checks if fields are valid.

It should be used after creating or updating a Schema (unmarshalling or direct instantiation without `NewSchema`).

Returns `*InvalidSchemaError` on error.

Jump to

Keyboard shortcuts

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