codegen

package
v0.9.5 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2020 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EncodingJson  = "encoding/json"
	Unmarshal     = "Unmarshal"
	UnmarshalJSON = "UnmarshalJSON"
	Marshal       = "Marshal"
	MarshalJSON   = "MarshalJSON"

	Codec                = "codec"
	RestLiEncode         = "RestLiEncode"
	RestLiDecode         = "RestLiDecode"
	RestLiCodec          = "RestLiCodec"
	RestLiUrlEncoder     = "RestLiUrlEncoder"
	RestLiReducedEncoder = "RestLiReducedEncoder"

	PopulateDefaultValues = "populateDefaultValues"
	ValidateUnionFields   = "validateUnionFields"

	NetHttp = "net/http"

	ProtocolPackage = "github.com/bored-engineer/go-restli/protocol"
)
View Source
const (
	RestLiClient = "RestLiClient"

	FormatQueryUrl     = "FormatQueryUrl"
	ResourcePath       = "ResourcePath"
	ResourceEntityPath = "ResourceEntityPath"
	DoAndIgnore        = "DoAndIgnore"
	DoAndDecode        = "DoAndDecode"
	DoAndDecodeResult  = "doAndDecodeResult"

	FindBy = "FindBy"

	ReqVar   = "req"
	ResVar   = "res"
	UrlVar   = "url"
	PathVar  = "path"
	PatchVar = "patch"

	ClientReceiver      = "c"
	ClientType          = "client"
	ClientInterfaceType = "Client"
)
View Source
const CreateParam = "create"
View Source
const EncodeFinderParams = "EncodeFinderParams"
View Source
const PartialUpdateDeleteParam = "delete"
View Source
const PartialUpdateSetParam = "set"
View Source
const UpdateParam = "update"

Variables

View Source
var (
	PackagePrefix string

	CommentWrapWidth = 120

	HeaderTemplate = template.Must(template.New("header").Parse(`DO NOT EDIT

Code automatically generated by go-restli
Source file: {{.SourceFile}}`))
)
View Source
var Logger = log.New(os.Stderr, "[go-restli] ", log.LstdFlags|log.Lshortfile)
View Source
var PrimitiveTypes = []PrimitiveType{
	{Type: "int32", /* contains filtered or unexported fields */},
	{Type: "int64", /* contains filtered or unexported fields */},
	{Type: "float32", /* contains filtered or unexported fields */},
	{Type: "float64", /* contains filtered or unexported fields */},
	{Type: "bool", /* contains filtered or unexported fields */},
	{Type: "string", /* contains filtered or unexported fields */},
	{Type: "bytes", /* contains filtered or unexported fields */},
}
View Source
var TypeRegistry = make(typeRegistry)

Functions

func AddFuncOnReceiver

func AddFuncOnReceiver(def *Statement, receiver, typeName, funcName string) *Statement

func AddMarshalJSON

func AddMarshalJSON(def *Statement, receiver, typeName string, f func(def *Group)) *Statement

func AddRestLiDecode

func AddRestLiDecode(def *Statement, receiver, typeName string, f func(def *Group)) *Statement

func AddRestLiEncode

func AddRestLiEncode(def *Statement, receiver, typeName string, f func(def *Group)) *Statement

func AddStringer

func AddStringer(def *Statement, receiver, typeName string, f func(def *Group)) *Statement

func AddUnmarshalJSON

func AddUnmarshalJSON(def *Statement, receiver, typeName string, f func(def *Group)) *Statement

func AddWordWrappedComment

func AddWordWrappedComment(code *Statement, comment string) *Statement

func Bytes

func Bytes() *Statement

func ExportedIdentifier

func ExportedIdentifier(identifier string) string

func FqcpToPackagePath

func FqcpToPackagePath(fqcp string) string

func GenerateAllImportsFile

func GenerateAllImportsFile(outputDir string, codeFiles []*CodeFile) error

func GenerateCode

func GenerateCode(specBytes []byte, outputDir string) error

func IfErrReturn

func IfErrReturn(def *Group, results ...Code) *Group

func JsonFieldTag

func JsonFieldTag(name string, optional bool) map[string]string

func PrivateIdentifier

func PrivateIdentifier(identifier string) string

func ReceiverName

func ReceiverName(typeName string) string

func RestLiMethod

func RestLiMethod(method protocol.RestLiMethod) *Statement

func WriteJenFile

func WriteJenFile(filename string, file *File) error

Types

type CodeFile

type CodeFile struct {
	SourceFile  string
	PackagePath string
	Filename    string
	Code        *Statement
}

func (*CodeFile) Identifier

func (f *CodeFile) Identifier() string

func (*CodeFile) Write

func (f *CodeFile) Write(outputDir string) (filename string, err error)

type ComplexType

type ComplexType interface {
	GetIdentifier() Identifier
	GetSourceFile() string
	InnerTypes() IdentifierSet
	GenerateCode() *jen.Statement
}

type Enum

type Enum struct {
	NamedType
	Symbols     []string
	SymbolToDoc map[string]string
}

func (*Enum) GenerateCode

func (e *Enum) GenerateCode() (def *Statement)

func (*Enum) InnerTypes

func (e *Enum) InnerTypes() IdentifierSet

func (*Enum) SymbolIdentifier

func (e *Enum) SymbolIdentifier(symbol string) string

type Field

type Field struct {
	Type         RestliType
	Name         string
	Doc          string
	IsOptional   bool
	DefaultValue *string
}

func (*Field) IsPointer

func (f *Field) IsPointer() bool

type FinderParams

type FinderParams Record

func (*FinderParams) GenerateCode

func (p *FinderParams) GenerateCode(f *Method) *Statement

type Fixed

type Fixed struct {
	NamedType
	Size int
}

func (*Fixed) GenerateCode

func (f *Fixed) GenerateCode() (def *Statement)

func (*Fixed) InnerTypes

func (f *Fixed) InnerTypes() IdentifierSet

type GoRestliSpec

type GoRestliSpec struct {
	DataTypes []struct {
		Enum    *Enum
		Fixed   *Fixed
		Record  *Record
		Typeref *Typeref
	}
	Resources []Resource
}

func (*GoRestliSpec) GenerateClientCode

func (s *GoRestliSpec) GenerateClientCode() (codeFiles []*CodeFile)

func (*GoRestliSpec) UnmarshalJSON

func (s *GoRestliSpec) UnmarshalJSON(data []byte) error

type Identifier

type Identifier struct {
	Name      string `json:"name"`
	Namespace string `json:"namespace"`
}

func (*Identifier) GetIdentifier

func (i *Identifier) GetIdentifier() Identifier

func (Identifier) GetQualifiedClasspath

func (i Identifier) GetQualifiedClasspath() string

func (Identifier) PackagePath

func (i Identifier) PackagePath() string

func (*Identifier) Receiver

func (i *Identifier) Receiver() string

func (*Identifier) Resolve

func (i *Identifier) Resolve() ComplexType

func (Identifier) String

func (i Identifier) String() string

type IdentifierSet

type IdentifierSet map[Identifier]bool

func (IdentifierSet) Add

func (set IdentifierSet) Add(id Identifier)

func (IdentifierSet) AddAll

func (set IdentifierSet) AddAll(other IdentifierSet)

func (IdentifierSet) Get

func (set IdentifierSet) Get(id Identifier) bool

func (IdentifierSet) Remove

func (set IdentifierSet) Remove(id Identifier)

func (IdentifierSet) String

func (set IdentifierSet) String() string

type Method

type Method struct {
	MethodType MethodType
	Name       string
	Doc        string
	Path       string
	OnEntity   bool
	PathKeys   []PathKey
	Params     []Field
	Return     *RestliType
}

func (*Method) RestLiMethod

func (m *Method) RestLiMethod() protocol.RestLiMethod

type MethodType

type MethodType string
const (
	REST_METHOD MethodType = "REST_METHOD"
	ACTION      MethodType = "ACTION"
	FINDER      MethodType = "FINDER"
)

type NamedType

type NamedType struct {
	Identifier
	SourceFile string
	Doc        string
}

func (*NamedType) GetSourceFile

func (t *NamedType) GetSourceFile() string

type Path

type Path []Identifier

func (Path) Add

func (p Path) Add(id Identifier) Path

func (Path) IntroducesCycle

func (p Path) IntroducesCycle(nextNode Identifier) Path

func (Path) SeenNode

func (p Path) SeenNode(id Identifier) bool

type PathKey

type PathKey struct {
	Name string
	Type RestliType
}

type PrimitiveType

type PrimitiveType struct {
	Type string
	// contains filtered or unexported fields
}

func (*PrimitiveType) Cast

func (p *PrimitiveType) Cast(accessor *Statement) *Statement

func (*PrimitiveType) GoType

func (p *PrimitiveType) GoType() *Statement

func (*PrimitiveType) IsBytes

func (p *PrimitiveType) IsBytes() bool

func (*PrimitiveType) UnmarshalJSON

func (p *PrimitiveType) UnmarshalJSON(data []byte) error

type Record

type Record struct {
	NamedType
	Fields []Field
	// contains filtered or unexported fields
}

func (*Record) GenerateCode

func (r *Record) GenerateCode() (def *Statement)

func (*Record) InnerTypes

func (r *Record) InnerTypes() IdentifierSet

type Resource

type Resource struct {
	Namespace        string
	Doc              string
	SourceFile       string
	RootResourceName string
	ResourceSchema   *RestliType
	Methods          []*Method
}

func (*Resource) GenerateActionCode

func (r *Resource) GenerateActionCode(a *Method) *CodeFile

func (*Resource) GenerateCode

func (r *Resource) GenerateCode() []*CodeFile

func (*Resource) GenerateFinderCode

func (r *Resource) GenerateFinderCode(f *Method) *CodeFile

func (*Resource) NewCodeFile

func (r *Resource) NewCodeFile(filename string) *CodeFile

func (*Resource) PackagePath

func (r *Resource) PackagePath() string

type RestliType

type RestliType struct {
	Primitive *PrimitiveType
	Reference *Identifier
	Array     *RestliType
	Map       *RestliType
	Union     *UnionType
}

func (*RestliType) GoType

func (t *RestliType) GoType() *Statement

func (*RestliType) InnerTypes

func (t *RestliType) InnerTypes() IdentifierSet

func (*RestliType) IsMapOrArray

func (t *RestliType) IsMapOrArray() bool

func (*RestliType) IsUnion

func (t *RestliType) IsUnion() bool

func (*RestliType) PointerType

func (t *RestliType) PointerType() *Statement

func (*RestliType) ReferencedType

func (t *RestliType) ReferencedType() *Statement

func (*RestliType) RestLiEncodeModel

func (t *RestliType) RestLiEncodeModel(encoder string, accessor *Statement) (*Statement, bool)

func (*RestliType) RestLiReducedEncodeModel

func (t *RestliType) RestLiReducedEncodeModel(accessor *Statement) (def *Statement, hasError bool)

func (*RestliType) RestLiURLEncodeModel

func (t *RestliType) RestLiURLEncodeModel(accessor *Statement) (def *Statement, hasError bool)

func (*RestliType) UnmarshalJSON

func (t *RestliType) UnmarshalJSON(data []byte) error

func (*RestliType) WriteToBuf

func (t *RestliType) WriteToBuf(def *Group, accessor *Statement)

type Typeref

type Typeref struct {
	NamedType
	Ref RestliType
}

func (*Typeref) GenerateCode

func (r *Typeref) GenerateCode() (def *Statement)

func (*Typeref) InnerTypes

func (r *Typeref) InnerTypes() IdentifierSet

type UnionMember

type UnionMember struct {
	Type  RestliType
	Alias string
}

type UnionType

type UnionType []UnionMember

func (*UnionType) GoType

func (u *UnionType) GoType() *Statement

func (*UnionType) InnerModels

func (u *UnionType) InnerModels() IdentifierSet

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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