Documentation
¶
Overview ¶
Package schema represents the tree structure of an API schema.
For more information, refer to the main "steamweb" package documentation.
Index ¶
- Variables
- type Interface
- type InterfaceGroupsByName
- type InterfaceKey
- type InterfaceNotFoundError
- type Interfaces
- type InterfacesIndex
- type InvalidInterfaceError
- type InvalidInterfaceNameError
- type InvalidMethodError
- type InvalidMethodHTTPMethodError
- type InvalidMethodNameError
- type InvalidMethodVersionError
- type InvalidSchemaError
- type Method
- type MethodGroupsByName
- type MethodKey
- type MethodNotFoundError
- type MethodParam
- type MethodParams
- type Methods
- type MethodsIndex
- type RequiredParameterError
- type Schema
Constants ¶
This section is empty.
Variables ¶
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 ¶
MustNewInterface is like `NewInterface` but panics on 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 ¶
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 ¶
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.
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 ¶
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 ¶
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 ¶
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 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 ¶
FormatVersion returns the formatted version string (in the format "v<version>") to be used as a request path parameter.
func (*Method) Validate ¶
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.
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 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 ¶
MustNewMethods is like `NewMethods` but panics on errors.
func (Methods) Get ¶
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.
type MethodsIndex ¶
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.