api

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Any = &anyType{}

Any is used for undefined/irrelevant types

View Source
var Bool = &basicType{boolT, "bool", "boolean"}

Bool represents basic bool types

View Source
var Error = &errorType{}

Error is used for errors types

View Source
var Float32 = &basicType{float32T, "float32", "number"}

Float32 represents basic float32 types

View Source
var Float64 = &basicType{float64T, "float64", "number"}

Float64 represents basic float64 types

View Source
var Int = &basicType{intT, "int", "integer"}

Int represents basic int types

View Source
var Int16 = &basicType{int16T, "int16", "integer"}

Int16 represents basic int16 types

View Source
var Int32 = &basicType{int32T, "int32", "integer"}

Int32 represents basic int32 types

View Source
var Int64 = &basicType{int64T, "int64", "integer"}

Int64 represents basic int64 types

View Source
var Int8 = &basicType{int8T, "int8", "integer"}

Int8 represents basic int8 types

View Source
var Integers = []Type{
	Int, Int8, Int16, Int32, Int64,
	Uint, Uint8, Uint16, Uint32, Uint64,
}

Integers contains a list of all integer types

View Source
var InvalidRequestResponse = Response{
	Description: "invalid request",
	Data: FieldMap{
		"error": {
			Type:        String,
			Description: "Error message",
			Required:    true,
		},
	},
}

InvalidRequestResponse defines response for invalid/failed requests

Numbers contains a list of all numeric types

View Source
var String = &basicType{stringT, "string", "string"}

String represents basic string types

View Source
var Uint = &basicType{uintT, "uint", "integer"}

Uint represents basic uint types

View Source
var Uint16 = &basicType{uint16T, "uint16", "integer"}

Uint16 represents basic uint16 types

View Source
var Uint32 = &basicType{uint32T, "uint32", "integer"}

Uint32 represents basic uint32 types

View Source
var Uint64 = &basicType{uint64T, "uint64", "integer"}

Uint64 represents basic uint64 types

View Source
var Uint8 = &basicType{uint8T, "uint8", "integer"}

Uint8 represents basic uint8 types

Functions

This section is empty.

Types

type ExtendedHandler

type ExtendedHandler struct {
	Description string
	Parameters  FieldMap
	Responses   map[string]Response
}

ExtendedHandler definition

func (*ExtendedHandler) ValidateParameters

func (f *ExtendedHandler) ValidateParameters(data map[string]interface{}) (map[string]interface{}, error)

ValidateParameters check if data matches with defined parameters and add defaults to data

type Field

type Field struct {
	// Type of value
	// 0/Invalid for undefined/any type
	Type Type

	// Description of field
	Description string

	// True if field is required
	Required bool

	// Default value if field is not required
	DefaultValue interface{}

	// Order index of field (should not be 0 if used)
	Order uint

	// Possible values for this field
	//  key: value for field
	//  value: description of value (or value as fallback)
	PossibleValues func() map[interface{}]string

	// True if only values from PossibleValues are valid
	OnlyPossibleValues bool
}

Field information for a value

func (Field) MarshalJSON

func (f Field) MarshalJSON() ([]byte, error)

MarshalJSON converts Field to JSON

func (Field) TypeName

func (f Field) TypeName() string

TypeName return the name of the type

type FieldList

type FieldList []Field

FieldList type with list of fields

func (FieldList) BaseName

func (t FieldList) BaseName() string

BaseName return the name of the type category

func (FieldList) Check

func (t FieldList) Check(value interface{}) bool

Check if the value matches the type

func (FieldList) Convert added in v0.6.0

func (t FieldList) Convert(value interface{}) (interface{}, error)

Convert given value to type if possible

func (FieldList) TypeName

func (t FieldList) TypeName() string

TypeName return the name of the type

func (FieldList) Validate

func (t FieldList) Validate(data []interface{}) ([]interface{}, error)

Validate check if data matches with defined fields and add defaults to data

type FieldMap

type FieldMap map[string]Field

FieldMap type with sub fields

func (FieldMap) BaseName

func (t FieldMap) BaseName() string

BaseName return the name of the type category

func (FieldMap) Check

func (t FieldMap) Check(value interface{}) bool

Check if the value matches the type

func (FieldMap) Convert added in v0.6.0

func (t FieldMap) Convert(value interface{}) (interface{}, error)

Convert given value to type if possible

func (FieldMap) Load

func (t FieldMap) Load(data map[string]interface{}) map[string]interface{}

Load data and fallback to default (ignores required flag)

func (FieldMap) SortedKeys

func (t FieldMap) SortedKeys() []string

SortedKeys returns list with sorted map keys (uses Order if set)

func (FieldMap) TypeName

func (t FieldMap) TypeName() string

TypeName return the name of the type

func (FieldMap) Validate

func (t FieldMap) Validate(data map[string]interface{}) (map[string]interface{}, error)

Validate check if data matches with defined fields and add defaults to data

type Function

type Function struct {
	Description string
	Arguments   FieldMap // order should be defined
	Response    FieldList
}

Function with positional arguments and response

func (*Function) BaseName

func (f *Function) BaseName() string

BaseName return the name of the type category

func (*Function) Check

func (f *Function) Check(value interface{}) bool

Check if the value matches the type

func (*Function) Convert added in v0.6.0

func (f *Function) Convert(value interface{}) (interface{}, error)

Convert given value to type if possible

func (*Function) TypeName

func (f *Function) TypeName() string

TypeName return the name of the type

func (*Function) ValidateArguments

func (f *Function) ValidateArguments(data []interface{}) ([]interface{}, error)

ValidateArguments check if data matches with defined parameters and add defaults to data

type Response

type Response struct {
	Description string

	// Data fields inside response
	Data FieldMap
}

Response information

type SimpleHandler

type SimpleHandler struct {
	Description string
	Parameters  FieldMap
	Response    FieldMap
}

SimpleHandler with named parameters and a single response

func (*SimpleHandler) ValidateParameters

func (f *SimpleHandler) ValidateParameters(data map[string]interface{}) (map[string]interface{}, error)

ValidateParameters check if data matches with defined parameters and add defaults to data

type Type

type Type interface {
	// Convert given value to type if possible
	Convert(value interface{}) (interface{}, error)

	// Check if the value matches the type
	Check(value interface{}) bool

	// TypeName return the name of the type
	TypeName() string

	// BaseName return the name of the type category
	BaseName() string
}

Type defines base interface of types

func Map

func Map(key, value Type) Type

Map returns a map with the given types

func Slice

func Slice(t Type) Type

Slice returns a slice type with the given sub element

func TypeFromTypeName

func TypeFromTypeName(name string) Type

TypeFromTypeName returns type from type name

func TypeFromValue

func TypeFromValue(val interface{}) Type

TypeFromValue returns type from value

Jump to

Keyboard shortcuts

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