Documentation
¶
Overview ¶
@TODO: add more documentation to this code, since it is more advanced code and can bring misunderstandnis.
Source provides way how to specify choices rest endpoint for given field ¶
This is proposal:
md := New()
userlist := md.Action(ACTION_POST).Field("result").From([]User{})
statusfield := userlist.Field("status")
statusfield.
Source("/api/user/status").
Action(action).
Mapping("result", "value", "display")
Index ¶
- Constants
- Variables
- func Debug()
- func ParseQuery(query string, action Action) (err error)
- func ParseTag(tag string) (string, tagOptions)
- func RegisterKind(f FieldTypeFunc, kind ...reflect.Kind)
- func RegisterType(f FieldTypeFunc, values ...interface{}) (err error)
- type Action
- type Choice
- type Choices
- type Field
- type FieldTypeFunc
- type Metadata
- type Source
Constants ¶
View Source
const ( ACTION_CREATE = "POST" ACTION_UPDATE = "POST" ACTION_RETRIEVE = "GET" ACTION_DELETE = "DELETE" )
View Source
const ( SOURCE_DEFAULT_VALUE_FIELD = "value" SOURCE_DEFAULT_DISPLAY_FIELD = "display" )
View Source
const ( FIELD_INVALID = "invalid" FIELD_ARRAY = "array" FIELD_STRUCT = "struct" FIELD_MAP = "map" FIELD_INTEGER = "integer" FIELD_UNSIGNED_INGETER = "unsigned" FIELD_STRING = "string" FIELD_BOOLEAN = "boolean" FIELD_FLOAT = "float" FIELD_DATETIME = "datetime" )
Variables ¶
View Source
var ( AVAILABLE_FIELDS = []string{FIELD_INVALID, FIELD_ARRAY, FIELD_STRUCT, FIELD_MAP, FIELD_INTEGER, FIELD_UNSIGNED_INGETER, FIELD_STRING, FIELD_BOOLEAN, FIELD_FLOAT, FIELD_DATETIME} )
Functions ¶
func ParseQuery ¶
ParseQuery parses query and udpates action query has following format
var1=type&var2=type
Where type is type of Field ¶
Example:
q=string&page=integer
func ParseTag ¶
parseTag splits a struct field's json tag into its name and comma-separated options.
func RegisterType ¶
func RegisterType(f FieldTypeFunc, values ...interface{}) (err error)
RegisterType provides register for custom types (e.g. time.Time)
Types ¶
type Action ¶
type Action interface {
// Description sets description for action
Description(string) Action
// GetDescription returns description
GetDescription() string
// Field adds or retrieves fields (recursively)
Field(...string) Field
// HasField returns whether field is set
HasField(names ...string) bool
// GetFieldNames returns names of all fields
GetFieldNames() []string
// From inspects given value and makes appropriate steps
From(v interface{}) Action
// GetData returns dynamic data (for json etc..)
GetData() map[string]interface{}
// MarshalJSON satisfies json marshaller
MarshalJSON() ([]byte, error)
// Debug enables debugging
Debug() Action
// ParseQueryParam parses
ParseQueryParam(query string) Action
// QueryParam returns or adds new query param
QueryParam(name string) Field
// RemoveQueryParam removes query param
RemoveQueryParam(name string) Action
// GetQueryParamNames returns names of all available query params
GetQueryParamNames() []string
// contains filtered or unexported methods
}
Action interface that describes single action (or http method)
type Choice ¶
type Choice struct {
Value interface{} `json:"value"`
Display string `json:"display"`
}
choice type
type Choices ¶
type Choices interface {
// Add adds new choice
Add(value interface{}, display string) Choices
// returns choices count
Count() int
// Support for marshalling
MarshalJSON() ([]byte, error)
}
Choices interface
type Field ¶
type Field interface {
// Field method returns field by names (recursively)
Field(...string) Field
// returns whether Field has field with given name
HasField(...string) bool
// return whether we have fields
NumFields() int
// GetFieldNames returns list of fields
GetFieldNames() []string
// Description sets help text for given field
Description(string) Field
// GetDescription is getter for HelpText
GetDescription() string
// Label sets label of field
Label(string) Field
// GetLabel is getter for Label
GetLabel() string
// RemoveField removes field from fields
RemoveField(string) (self Field)
// set required flag to field
Required(bool) (self Field)
// returns whether field is required
IsRequired() bool
// type is type of field
Type(string) Field
// GetType returns field type
GetType() string
// From reads target and sets data to field
From(interface{}) Field
// Data returns data representation in dynamic fashion (interface{})
GetData() map[string]interface{}
// MarshalJSON satisfies json marshaller
MarshalJSON() ([]byte, error)
// Choices returns choices
Choices() Choices
// Source
Source(path string) Source
// Debug enables debugging for metadata
Debug() Field
// contains filtered or unexported methods
}
Field interface
type FieldTypeFunc ¶
field type func returns Field by reflect value
type Metadata ¶
type Metadata interface {
// action returns either existing or newly created action
Action(method string) Action
// RemoveAction removes action
RemoveAction(method string) Metadata
// Name sets name to metadata
Name(string) Metadata
// GetName returns name of metadata
GetName() string
// Description sets description of metadata
Description(string) Metadata
// GetDescription returns description
GetDescription() string
// GetData returns dynamic data (for json etc..)
GetData() map[string]interface{}
// MarshalJSON satisfies json marshaller
MarshalJSON() ([]byte, error)
// Debug enables debugging for metadata
Debug() Metadata
// contains filtered or unexported methods
}
MetaData interface that describes heep endpoint methods
type Source ¶
type Source interface {
// Debug sets debug to source
Debug() Source
// Action sets action
Action(action Action) Source
// GetAction Returns action
GetAction() Action
// ResultField points to resultField
Result(field ...string) Source
// IsValid returns whether source is setup correct
IsValid() bool
// Value sets value field name
Value(value string) Source
// GetValue returns value field name
GetValue() string
// Display sets display field name
Display(display string) Source
// GetDisplay returns display field name
GetDisplay() string
// Path sets path to source
Path(string) Source
// GetPath returns path set for this source
GetPath() string
// Return data
GetData() map[string]interface{}
// MarshalJSON satisfies json marshal interface
MarshalJSON() ([]byte, error)
// contains filtered or unexported methods
}
Source is source for field value. This describes rest endpoint together with (optional) Metadata information.
Click to show internal directories.
Click to hide internal directories.