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 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 ¶
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 ¶
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 ¶
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 ¶
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"` }
FieldType holds information about the type of data that this Field stores.
func (FieldType) IsOptional ¶
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 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"` ImplementsJSONMarshaler bool `json:"implementsJSONMarshaler"` }
Object describes a data structure that is part of this definition.
type Parser ¶
type Parser struct { Verbose bool ExcludeInterfaces []string PackageName string // 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.