gingen

package
v0.0.0-...-225f367 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewProtocPlugin

func NewProtocPlugin() func(gen *protogen.Plugin) error

NewProtocPlugin new protoc plugin

Types

type Enum

type Enum struct {
	GoIdent         string // name of the generated Go type: the enum's name
	LeadingComments string
	Values          []EnumValue
	// contains filtered or unexported fields
}

Enum describes an enum.

func NewEnum

func NewEnum(f *protogen.GeneratedFile, enum *protogen.Enum) *Enum

NewEnum construct an enum.

func (Enum) P

func (e Enum) P()

P generates and print enum definition code into generated file.

type EnumValue

type EnumValue struct {
	LeadingComments string
	TrailingComment string
	ShortName       string // the short name of the declaration
	GoIdent         string // name of the generated Go type
	Type            string // Go type
	Number          int32  // the enum value as an integer.
}

EnumValue represents a enum value.

type Field

type Field struct {
	GoName string // filed name

	GoType string // field type, e.g int32, string, bool

	LeadingComments string
	Tags            []*Tag
}

Field describes field in structure.

func (Field) String

func (fi Field) String() string

String returns filed info as string.

e.g: Name string `json:"name"`

func (Field) TagByName

func (fi Field) TagByName(tagName string) *Tag

TagByName finds tag by name.

func (Field) TagByValue

func (fi Field) TagByValue(tagValue string) *Tag

TagByValue finds tag by value.

func (Field) TagStr

func (fi Field) TagStr() string

TagStr constructs and returns the formated tag string.

type FileInfo

type FileInfo struct {
	*protogen.File
	AllMessages []*protogen.Message
	AllEnums    []*protogen.Enum
	AllService  []*protogen.Service
}

FileInfo file info

func NewFileInfo

func NewFileInfo(file *protogen.File) *FileInfo

NewFileInfo constructs then file info.

type Generator

type Generator struct{}

func (*Generator) Run

func (g *Generator) Run()

type HTTPRule

type HTTPRule struct {
	Method       string
	Path         string
	HasPathParam bool
	PathParams   map[string]string
}

HTTPRule http rule

type Message

type Message struct {
	GoName          string
	LeadingComments string  // leading comments
	Fields          []Field // all fields
	// contains filtered or unexported fields
}

Message describes the message.

func NewMessage

func NewMessage(f *protogen.GeneratedFile, m *protogen.Message) *Message

NewMessage new message info

func (Message) FieldWithFileTag

func (mi Message) FieldWithFileTag() []Field

FieldWithFileTag returns all fields that have tag `file`.

func (Message) FieldWithFormTag

func (mi Message) FieldWithFormTag() []Field

FieldWithFormTag returns all fields that have tag `form`.

func (Message) FieldWithHeaderTag

func (mi Message) FieldWithHeaderTag() []Field

FieldWithHeaderTag returns all fields that have tag `header`.

func (Message) FieldWithJSONTag

func (mi Message) FieldWithJSONTag() []Field

FieldWithJSONTag returns all fields that have tag `json`.

func (Message) FieldWithPathTag

func (mi Message) FieldWithPathTag() []Field

FieldWithPathTag returns all fields that have tag `path`.

func (Message) FieldWithQueryTag

func (mi Message) FieldWithQueryTag() []Field

FieldWithQueryTag returns all fields that have tag `query`.

func (Message) FieldWithTag

func (mi Message) FieldWithTag(tagName string) []Field

FieldWithTag returns all fileds that has specified tag.

func (Message) HasFile

func (mi Message) HasFile() bool

HasFile returns true if there is field represents a file.

func (Message) HasFormParam

func (mi Message) HasFormParam() bool

HasFormParam returns true if there is at least one form param.

func (Message) HasHeaderParam

func (mi Message) HasHeaderParam() bool

HasHeaderParam returns true if there is at least one header param.

func (Message) HasQueryParam

func (mi Message) HasQueryParam() bool

HasQueryParam returns true if there is at least one query param.

func (Message) P

func (mi Message) P()

P generates definition code for message and print it into generated file.

func (Message) QueryFieldByTagKeyAndValue

func (mi Message) QueryFieldByTagKeyAndValue(key, value string) (Field, bool)

QueryFieldByTagKeyAndValue returns field that has tag which key_name=`key` and value = `value`

type Method

type Method struct {
	Name      string
	Request   *Message
	Response  *Message
	HTTPRules []*HTTPRule
	Comments  string
}

Method service's method

func (Method) HasHTTPRules

func (m Method) HasHTTPRules() bool

func (Method) HasPathParam

func (m Method) HasPathParam() bool

HasPathParam returns true if there is at least one http rule contains path param.

type ProtocPlugin

type ProtocPlugin struct {
	// contains filtered or unexported fields
}

ProtocPlugin is a plugin used to generate service implementation

func (*ProtocPlugin) Execute

func (p *ProtocPlugin) Execute() (err error)

Execute starts to generate file.

func (*ProtocPlugin) GenerateFile

func (p *ProtocPlugin) GenerateFile(file *FileInfo)

GenerateFile generates file.

type Service

type Service struct {
	LeadingComments string
	ServiceName     string
	Methods         []*Method
	// contains filtered or unexported fields
}

Service describes the service .

func NewService

func NewService(f *protogen.GeneratedFile, service *protogen.Service, withClient bool) *Service

NewService parses protogen.Service and returns it as Service.

func (*Service) P

func (s *Service) P()

P print generated code into genereted file

type Tag

type Tag struct {
	Key   string
	Value string
}

Tag describes tag info for structure filed.

e.g: json:"user_id"

func (Tag) String

func (ti Tag) String() string

String returns tag info as string.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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