generate

package
v0.0.0-...-b94e934 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OptionVersion              = "version"
	OptionImportPath           = "import_path"
	OptionAuthor               = "author"
	OptionProjectName          = "project_name"
	OptionShortDescription     = "short_description"
	OptionLongDescription      = "long_description"
	OptionCertsPath            = "certs_path"
	OptionPublicKeyName        = "public_key_name"
	OptionPrivateKeyName       = "private_key_name"
	OptionDockerPath           = "docker_path"
	OptionProjectNameCommander = "project_name_commander"
	OptionTransform            = "transform"
	OptionValidate             = "validate"
	OptionMiddlewareCORS       = "middleware.cors"
	OptionMiddlewareNoCache    = "middleware.no_cache"
	OptionMiddlewareLogger     = "middleware.logger"
	OptionMiddlewareSecure     = "middleware.secure"
	OptionMethod               = "method"
	OptionOrigins              = "origins"

	MiddlewareCORS    = "CORS"
	MiddlewareNoCache = "NoCache"
	MiddlewareLogger  = "Logger"
	MiddlewareSecure  = "Secure"
)
View Source
const (
	FileSyntax        = "syntax"
	FilePackage       = "package"
	FileImport        = "import"
	FieldRuleOptional = "optional"
	FieldRuleRepeated = "repeated"
	FieldRuleRequired = "required"
)
View Source
const (
	TokenFileKey          = "fileKey"
	TokenFileVal          = "fileVal"
	TokenRPCName          = "rpcName"
	TokenRPCIn            = "rpcIn"
	TokenRPCOut           = "rpcOut"
	TokenFileOptionKey    = "fileOptionKey"
	TokenFileOptionVal    = "fileOptionVal"
	TokenServiceKey       = "serviceKey"
	TokenServiceOptionKey = "serviceOptionKey"
	TokenServiceOptionVal = "serviceOptionVal"
	TokenRPCOptionKey     = "rpcOptionKey"
	TokenRPCOptionVal     = "rpcOptionVal"
	TokenMessageKey       = "messageKey"
	TokenFieldDataType    = "fieldDataType"
	TokenFieldKey         = "fieldKey"
	TokenFieldOptionKey   = "fieldOptionKey"
	TokenFieldOptionVal   = "fieldOptionVal"
	TokenRPCDone          = "rpcDone"
	TokenMessageDone      = "messageDone"
	TokenServiceDone      = "serviceDone"
	TokenFieldDone        = "fieldDone"
	TokenFieldRule        = "fieldRule"
)
View Source
const (
	TagNameValidate  = "validate"
	ValidateRequired = "required"
)

Variables

View Source
var (
	ErrorMismatchSyntax     = errors.New("Syntax mismatch on imports")
	ErrorNoImportsProvided  = errors.New("No imports provided")
	ErrorFieldInvalidSyntax = errors.New("Field import syntax invalid")
)
View Source
var (
	ValidateRequiredErr = errors.New("Failed Required Validation")
)

Functions

func Generate

func Generate(cfg Config)

func Merge

func Merge(proto *Proto, importedProtos ...Proto) (err error)

func MinusP

func MinusP(in string) string

func MinusStar

func MinusStar(in string) string

func RemoveUnusedFile

func RemoveUnusedFile(completeFilePath string)

func Scan

func Scan(fileBytes []byte) (tokens chan Token)

func ToCamelCase

func ToCamelCase(src string) (out string)

func ToDashCase

func ToDashCase(in string) (out string)

func Validate

func Validate(in interface{}) (err error)

Types

type Config

type Config struct {
	ProtoFilePath string
	Verbose       bool
	OutPath       string
	LogLevel      log.Level
}

type Degeneres

type Degeneres struct {
	GeneratorVersion     string
	Version              string `validate:"required"`
	ImportPath           string `validate:"required"`
	DockerPath           string
	Author               string `validate:"required"`
	ProjectName          string `validate:"required"`
	ProjectNameCommander string
	ProjectFolder        string
	ShortDescription     string
	LongDescription      string
	Origins              string
	Services             []DgService
	Messages             []DgMessage
	Inputs               []DgMessage

	ProtoPaths    []string
	ProtoFilePath string
}

func NewDegeneres

func NewDegeneres(proto Proto) (dg Degeneres, err error)

type DgEndpoint

type DgEndpoint struct {
	Name
	ServiceName     Name
	Pattern         string
	Middlewares     map[string]string
	MiddlewareNames string
	Methods         []Name
	Input           Name
	Output          Name

	ImportPath string
}

type DgField

type DgField struct {
	Name
	DataTypeName     Name
	DataType         string
	Transform        string
	Validate         string
	Rule             string
	IsRepeated       bool
	IsStruct         bool
	IsRepeatedStruct bool
}

type DgMessage

type DgMessage struct {
	Name
	Fields   []DgField
	RPCInput bool
}

type DgService

type DgService struct {
	Name
	ShortDescription string
	LongDescription  string
	Middlewares      map[string]string
	MiddlewareNames  string
	Endpoints        []DgEndpoint

	ImportPath string
}

type Field

type Field struct {
	Name     string
	DataType string
	Position string
	Rule     string
	Options  []Option
}

type KV

type KV struct {
	Key string
	Val string
}

type Message

type Message struct {
	Name     string
	Fields   []Field
	Imported bool
	RPCInput bool
}

type Name

type Name struct {
	Raw        string
	Dash       string
	Snake      string
	Camel      string
	Lower      string
	LowerDash  string
	LowerSnake string
	LowerCamel string
	Title      string
	TitleSnake string
	TitleCamel string
	Upper      string
	UpperSnake string
	UpperCamel string
}

type Option

type Option struct {
	Name  string
	Value string
}

type Proto

type Proto struct {
	Syntax   string
	Package  string
	Imports  []string
	Options  []Option
	Services []Service
	Messages []Message

	ProtoPaths    []string
	ProtoFilePath string
}

func NewProto

func NewProto() (proto Proto)

func Parse

func Parse(tokens chan Token) (proto Proto)

func UnmarshalFile

func UnmarshalFile(filePath string) (proto Proto, err error)

type RPC

type RPC struct {
	Name    string
	Input   string
	Output  string
	Options []Option
}

type Scanner

type Scanner struct {
	State    State
	TokenCh  chan Token
	InputBuf *bytes.Buffer
}

func NewScanner

func NewScanner(inputBytes []byte, tokenCh chan Token) Scanner

func (Scanner) Emit

func (s Scanner) Emit(token Token)

func (Scanner) FieldOptionsState

func (s Scanner) FieldOptionsState() State

func (Scanner) FileState

func (s Scanner) FileState() State

func (Scanner) MessageState

func (s Scanner) MessageState() State

func (Scanner) RPCState

func (s Scanner) RPCState() State

func (Scanner) ServiceState

func (s Scanner) ServiceState() State

func (Scanner) Start

func (s Scanner) Start()

type Service

type Service struct {
	Name    string
	Options []Option
	RPCs    []RPC
}

type State

type State func() State

type Template

type Template struct {
	TemplateName string
	FileName     string
	Data         interface{}
}

type Token

type Token struct {
	Name  string
	Value string
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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