Documentation
¶
Index ¶
- Variables
- func Split(src string) (entries []string)
- type Definition
- func (d *Definition) Example(o Object) (map[string]interface{}, error)
- func (d *Definition) ExampleP(o *Object) (map[string]interface{}, error)
- func (d *Definition) Object(name string) (*Object, error)
- func (d *Definition) ObjectIsInput(name string) bool
- func (d *Definition) ObjectIsOutput(name string) bool
- type Field
- type FieldTag
- type FieldType
- type Method
- type MethodGroup
- type Object
- type Parser
- type Service
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound is returned when an Object is not found.
Functions ¶
func Split ¶
Split splits the camelcase word and returns a list of words. It also supports digits. Both lower camel case and upper camel case are supported. For more info please check: http://en.wikipedia.org/wiki/CamelCase
Examples
"" => [""] "lowercase" => ["lowercase"] "Class" => ["Class"] "MyClass" => ["My", "Class"] "MyC" => ["My", "C"] "HTML" => ["HTML"] "PDFLoader" => ["PDF", "Loader"] "AString" => ["A", "String"] "SimpleXMLParser" => ["Simple", "XML", "Parser"] "vimRPCPlugin" => ["vim", "RPC", "Plugin"] "GL11Version" => ["GL", "11", "Version"] "99Bottles" => ["99", "Bottles"] "May5" => ["May", "5"] "BFG9000" => ["BFG", "9000"] "BöseÜberraschung" => ["Böse", "Überraschung"] "Two spaces" => ["Two", " ", "spaces"] "BadUTF8\xe2\xe2\xa1" => ["BadUTF8\xe2\xe2\xa1"]
Splitting rules
- If string is not valid UTF-8, return it without splitting as single item array.
- Assign all unicode characters into one of 4 sets: lower case letters, upper case letters, numbers, and all other characters.
- Iterate through characters of string, introducing splits between adjacent characters that belong to different sets.
- Iterate through array of split strings, and if a given string is upper case: if subsequent string is lower case: move last character of upper case string to beginning of lower case string
Example ¶
for _, c := range []string{
"",
"lowercase",
"Class",
"MyClass",
"MyC",
"HTML",
"PDFLoader",
"AString",
"SimpleXMLParser",
"vimRPCPlugin",
"GL11Version",
"99Bottles",
"May5",
"BFG9000",
"BöseÜberraschung",
"Two spaces",
"BadUTF8\xe2\xe2\xa1",
} {
fmt.Printf("%#v => %#v\n", c, Split(c))
}
Output: "" => []string{} "lowercase" => []string{"lowercase"} "Class" => []string{"Class"} "MyClass" => []string{"My", "Class"} "MyC" => []string{"My", "C"} "HTML" => []string{"HTML"} "PDFLoader" => []string{"PDF", "Loader"} "AString" => []string{"A", "String"} "SimpleXMLParser" => []string{"Simple", "XML", "Parser"} "vimRPCPlugin" => []string{"vim", "RPC", "Plugin"} "GL11Version" => []string{"GL", "11", "Version"} "99Bottles" => []string{"99", "Bottles"} "May5" => []string{"May", "5"} "BFG9000" => []string{"BFG", "9000"} "BöseÜberraschung" => []string{"Böse", "Überraschung"} "Two spaces" => []string{"Two", " ", "spaces"} "BadUTF8\xe2\xe2\xa1" => []string{"BadUTF8\xe2\xe2\xa1"}
Types ¶
type Definition ¶
type Definition struct {
// PackageName is the name of the package.
PackageName string `json:"packageName"`
// Services are the services described in this definition.
Services []Service `json:"services"`
// Objects are the structures that are used throughout this definition.
Objects []Object `json:"objects"`
// Imports is a map of Go imports that should be imported into
// Go code.
Imports map[string]string `json:"imports"`
}
Definition describes an Oto definition.
func (*Definition) Example ¶ added in v0.11.0
func (d *Definition) Example(o Object) (map[string]interface{}, error)
Example generates an object that is a realistic example of this object. Examples are read from the docs. This is experimental.
func (*Definition) ExampleP ¶ added in v0.12.0
func (d *Definition) ExampleP(o *Object) (map[string]interface{}, error)
ExampleP is a pointer version of Example.
func (*Definition) Object ¶
func (d *Definition) Object(name string) (*Object, error)
Object looks up an object by name. Returns ErrNotFound error if it cannot find it.
func (*Definition) ObjectIsInput ¶ added in v0.10.7
func (d *Definition) ObjectIsInput(name string) bool
ObjectIsInput gets whether this object is a method input (request) type or not.\ Returns true if any method.InputObject.ObjectName matches name.
func (*Definition) ObjectIsOutput ¶ added in v0.10.7
func (d *Definition) ObjectIsOutput(name string) bool
ObjectIsOutput gets whether this object is a method output (response) type or not. Returns true if any method.OutputObject.ObjectName matches name.
type Field ¶
type Field struct {
Name string `json:"name"`
NameLowerCamel string `json:"nameLowerCamel"`
Type FieldType `json:"type"`
OmitEmpty bool `json:"omitEmpty"`
Comment string `json:"comment"`
Tag string `json:"tag"`
ParsedTags map[string]FieldTag `json:"parsedTags"`
Example interface{} `json:"example"`
// Metadata are typed key/value pairs extracted from the
// comments.
Metadata map[string]interface{} `json:"metadata"`
}
Field describes the field inside an Object.
type FieldTag ¶
type FieldTag struct {
// Value is the value of the tag.
Value string `json:"value"`
// Options are the options for the tag.
Options []string `json:"options"`
}
FieldTag is a parsed tag. For more information, see Struct Tags in Go.
type FieldType ¶
type FieldType struct {
TypeID string `json:"typeID"`
TypeName string `json:"typeName"`
ObjectName string `json:"objectName"`
ExternalObjectName string `json:"externalObjectName"`
// CleanObjectName is the ObjectName with * removed
// for pointer types.
CleanObjectName string `json:"cleanObjectName"`
ObjectNameLowerCamel string `json:"objectNameLowerCamel"`
Multiple bool `json:"multiple"`
Package string `json:"package"`
IsObject bool `json:"isObject"`
JSType string `json:"jsType"`
TSType string `json:"tsType"`
SwiftType string `json:"swiftType"`
DartType string `json:"dartType"`
}
FieldType holds information about the type of data that this Field stores.
func (FieldType) IsOptional ¶ added in v0.11.1
IsOptional returns true for pointer types (optional).
type Method ¶
type Method struct {
Name string `json:"name"`
NameLowerCamel string `json:"nameLowerCamel"`
InputObject FieldType `json:"inputObject"`
OutputObject FieldType `json:"outputObject"`
Comment string `json:"comment"`
// Metadata are typed key/value pairs extracted from the
// comments.
Metadata map[string]interface{} `json:"metadata"`
}
Method describes a method that a Service can perform.
type MethodGroup ¶ added in v0.20.0
type MethodGroup struct {
// Metadata are the metadata fields that are shared.
Metadata map[string]interface{}
// Methods are the methods that share the metadata.
Methods []Method
}
MethodGroup is a group of methods that share the same metadata.
type Object ¶
type Object struct {
TypeID string `json:"typeID"`
ObjectName string `json:"objectName"`
ExternalObjectName string `json:"externalObjectName"`
Name string `json:"name"`
Imported bool `json:"imported"`
Fields []Field `json:"fields"`
Comment string `json:"comment"`
// Metadata are typed key/value pairs extracted from the
// comments.
Metadata map[string]interface{} `json:"metadata"`
}
Object describes a data structure that is part of this definition.
type Parser ¶
type Parser struct {
Verbose bool
ExcludeInterfaces []string
PackageName string
// SuppressErrorField suppresses the Error field in output objects.
SuppressErrorField bool
// contains filtered or unexported fields
}
Parser parses Oto Go definition packages.
func New ¶
New makes a fresh parser using the specified patterns. The patterns should be the args passed into the tool (after any flags) and will be passed to the underlying build system.
func (*Parser) Parse ¶
func (p *Parser) Parse() (Definition, error)
Parse parses the files specified, returning the definition.
type Service ¶
type Service struct {
Name string `json:"name"`
Methods []Method `json:"methods"`
Comment string `json:"comment"`
// Metadata are typed key/value pairs extracted from the
// comments.
Metadata map[string]interface{} `json:"metadata"`
}
Service describes a service, akin to an interface in Go.
func (Service) MethodsByMetadata ¶ added in v0.18.0
func (s Service) MethodsByMetadata(field string) []MethodGroup