definition

package
v0.0.0-...-d5b3e22 Latest Latest
Warning

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

Go to latest
Published: Aug 10, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned when an Object is not found.

Functions

func ParseParams

func ParseParams(s string) (map[string]interface{}, error)

ParseParams returns a map of data parsed from the params string.

Types

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"`
	IsPointer  bool   `json:"isPointer"`
	// 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"`
	PHPType              string `json:"phpType"`
}

FieldType holds information about the type of data that this Field stores.

func (FieldType) IsOptional

func (f FieldType) IsOptional() bool

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"`
	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

	Exclusions []string
	// contains filtered or unexported fields
}

Parser parses Oto Go definition packages.

func NewParser

func NewParser(patterns ...string) *Parser

NewParser 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) ParseWithParams

func (p *Parser) ParseWithParams(params map[string]interface{}) (*Root, error)

type Root

type Root 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"`
	// Params contains additional data parsed from command line arguments
	Params map[string]interface{} `json:"params"`
}

Root contains all service definitions and will be passed to template.

func (*Root) Example

func (d *Root) 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 (*Root) ExampleP

func (d *Root) ExampleP(o *Object) (map[string]interface{}, error)

ExampleP is a pointer version of Example.

func (*Root) Object

func (d *Root) Object(name string) (*Object, error)

Object looks up an object by name. Returns ErrNotFound error if it cannot find it.

func (*Root) ObjectIsInput

func (d *Root) 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 (*Root) ObjectIsOutput

func (d *Root) 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 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.

Jump to

Keyboard shortcuts

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