schema

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2020 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package schema represents the tree structure of an API schema.

For more information, refer to the main "geyser" 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"`
	Undocumented bool    `json:"undocumented"`
	// contains filtered or unexported fields
}

Interface holds the specification of an API interface.

The struct should be read-only.

func (*Interface) Key

func (i *Interface) Key() (InterfaceKey, error)

Key returns the key identifying the 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.

Key parses the interface name and extracts the base name and the AppID from the name.

Returns errors described in `Validate`.

func (*Interface) Validate

func (i *Interface) Validate() error

Validate checks if the interface and all its methods are valid.

Returns an error of type `*InvalidInterfaceNameError` if the interface name is invalid.

Returns errors described in `Methods.Validate`.

type InterfaceKey

type InterfaceKey struct {
	Name  string
	AppID uint32
}

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

type InterfaceMethodNotFoundError

type InterfaceMethodNotFoundError struct {
	Key MethodKey
}

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

func (InterfaceMethodNotFoundError) Error

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

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 collection.

Returns errors described in `Interface.Validate`.

func (Interfaces) Get

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

Get returns the interface with given key.

Returns an error of type `*InterfaceNotFoundError` if none was found.

Returns errors described in `Interface.Key`.

func (Interfaces) GroupByBaseName

func (c Interfaces) GroupByBaseName() (map[string]InterfacesGroup, error)

GroupByName groups the interfaces by base name.

The definition of base name is described in `Interface.Key`.

Returns errors described in `Interface.Key`.

func (Interfaces) Validate

func (c Interfaces) Validate() error

Validate checks if all contained interfaces are valid.

Returns errors described in `Interface.Validate`.

type InterfacesGroup

type InterfacesGroup map[InterfaceKey]*Interface

InterfacesGroup is a group of `Interface`s with the same base name.

The definition of base name is described in `Interface.Key`.

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. Group consumers can assume it's consistent.

Behavior of inconsistent groups is undefined.

func (InterfacesGroup) AppIDs

func (g InterfacesGroup) AppIDs() []uint32

AppIDs collects the AppID of all interfaces in the group.

Interfaces with no AppID (0) are omitted.

func (InterfacesGroup) GroupMethods

func (g InterfacesGroup) GroupMethods() (map[string]MethodsGroup, error)

GroupMethods groups interfaces methods by method name.

Returns errors described in `Methods.GroupByName`.

func (InterfacesGroup) Name

func (g InterfacesGroup) Name() (name string)

Name returns the common base name of all interfaces in the group.

The definition of base name is described in `Interface.Key`.

type InvalidInterfaceNameError

type InvalidInterfaceNameError struct {
	Interface *Interface
	Err       error
}

InvalidInterfaceNameError is returned when an interface has an invalid name.

func (InvalidInterfaceNameError) Error

type InvalidMethodHTTPMethodError

type InvalidMethodHTTPMethodError struct {
	Method *Method
}

InvalidMethodHTTPMethodError is returned when a method has an invalid version.

func (InvalidMethodHTTPMethodError) Error

type InvalidMethodNameError

type InvalidMethodNameError struct {
	Method *Method
}

InvalidMethodNameError is returned when a method has an invalid name.

func (InvalidMethodNameError) Error

type InvalidMethodVersionError

type InvalidMethodVersionError struct {
	Method *Method
}

InvalidMethodVersionError is returned when a method has an invalid version.

func (InvalidMethodVersionError) Error

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.

The struct should be read-only.

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, error)

Key returns the key identifying the method.

Returns errors described in `Validate`.

func (*Method) Validate

func (m *Method) Validate() error

Validate checks if the method is valid.

Returns an error of type `*InvalidMethodNameError` if the method has an invalid name.

Returns an error of type `*InvalidMethodVersionError` if the method has an invalid version.

Returns an error of type `*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 MethodKey

type MethodKey struct {
	Name    string
	Version int
}

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

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.

The struct should be read-only.

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 collection.

func (MethodParams) ValidateParams

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

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

Returns errors described in `MethodParam.ValidateParam`.

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 if it returned an error.

func NewMethods

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

NewMethods creates a new collection.

Returns errors described in `Method.Validate`.

func (Methods) Get

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

Get returns the method with the given key.

Returns an error of type `*InterfaceMethodNotFoundError` if none was found.

Returns errors described in `Method.Key`.

func (Methods) GroupByName

func (c Methods) GroupByName() (map[string]MethodsGroup, error)

GroupByName groups the methods by name.

Returns errors described in `Method.Key`.

func (Methods) Validate

func (c Methods) Validate() error

Validate checks if all contained methods are valid.

Returns errors described in `Method.Validate`.

type MethodsGroup

type MethodsGroup map[MethodKey]*Method

MethodsGroup is a group of `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. Group consumers can assume it's consistent.

Behavior of inconsistent groups is undefined.

func (MethodsGroup) Versions

func (g MethodsGroup) Versions() []int

Versions collects the versions of all methods in the group.

type RequiredParameterError

type RequiredParameterError struct {
	Param *MethodParam
}

RequiredParameterError is returned when a required parameter is missing.

func (RequiredParameterError) Error

type Schema

type Schema struct {
	Host       string     `json:"host"`
	Interfaces Interfaces `json:"interfaces"`
}

Schema is the root of an API schema specification.

func (*Schema) Validate

func (s *Schema) Validate() error

Validate checks if all contained interfaces are valid.

Returns errors described in `Interfaces.Validate`

Jump to

Keyboard shortcuts

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