parser

package
v1.1.30 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package parser is parsed proto file to struct

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetProtoFileDir

func GetProtoFileDir(protoPath string) string

func GetProtoPkgName

func GetProtoPkgName(importPath string) string

Types

type Field

type Field struct {
	Name           string // field name
	GoType         string // field go type
	GoTypeCrossPkg string // field go type cross package
	Comment        string // field comment
	FieldType      string // field type
	IsList         bool   // is list
	IsMap          bool   // is map
	ImportPkgName  string // e.g. anypb
	ImportPkgPath  string // import path e.g. google.golang.org/protobuf/types/known/anypb
}

Field message field

func (Field) GoTypeZero

func (r Field) GoTypeZero() string

GoTypeZero default zero value for type

type PbService

type PbService struct {
	Name      string           // Greeter
	LowerName string           // greeter first character to lower
	Methods   []*ServiceMethod // service methods

	CutServiceName      string // GreeterService --> Greeter
	LowerCutServiceName string // GreeterService --> greeter

	ImportPkgMap      map[string]string // e.g. `userV1`:`userV1 "user/api/user/v1"`
	FieldImportPkgMap map[string]string // e.g. `userV1`:`userV1 "user/api/user/v1"`

	ProtoFileDir string // e.g. api/user/v1
	ProtoPkgName string // e.g. userV1
}

PbService service fields

func GetServices

func GetServices(file *protogen.File) []*PbService

GetServices parse protobuf services

func (*PbService) RandNumber

func (s *PbService) RandNumber() int

RandNumber rand number 1~100

type RPCMethod

type RPCMethod struct {
	Name       string // SayHello
	Num        int    // one rpc RPCMethod can correspond to multiple http requests
	Request    string // SayHelloReq
	Reply      string // SayHelloResp
	InvokeType int    // 0:unary, 1: client-side streaming, 2: server-side streaming, 3: bidirectional streaming

	// http_rule
	Path         string // rule
	Method       string // HTTP Method
	Body         string
	ResponseBody string

	CustomKind string
	Selector   string
	// if Selector is [ctx], and IsPassGinContext is true
	// if true, pass gin.Context to the rpc method
	IsPassGinContext bool
	// if Selector is [no_bind], IsPassGinContext and IsPassGinContext are both true
	// if true, ignore c.ShouldBindXXX for this method, you must use c.ShouldBindXXX() in rpc method
	IsIgnoreShouldBind bool

	RequestImportPkgName string // e.g. empty or userV1
	ReplyImportPkgName   string // e.g. empty or userV1

	ProtoSelfPkgPath string              // e.g. "module/api/user/v1"
	ImportPkgPaths   map[string]struct{} // exclude ProtoSelfPkgPath
}

RPCMethod describes a rpc method

func (*RPCMethod) HandlerName

func (m *RPCMethod) HandlerName() string

HandlerName for gin handler name

func (*RPCMethod) HasPathParams

func (m *RPCMethod) HasPathParams() bool

HasPathParams whether to include routing parameters

func (*RPCMethod) InitPathParams

func (m *RPCMethod) InitPathParams()

InitPathParams conversion parameter routing {xx} --> :xx

type ServiceMethod

type ServiceMethod struct {
	MethodName    string // Create
	Request       string // CreateRequest
	RequestFields []*Field
	Reply         string // CreateReply
	ReplyFields   []*Field
	Comment       string // e.g. Create a record
	InvokeType    int    // 0:unary, 1: client-side streaming, 2: server-side streaming, 3: bidirectional streaming

	ServiceName         string // Greeter
	LowerServiceName    string // greeter first character to lower
	LowerCutServiceName string // GreeterService --> greeter

	// http_rule
	Path   string // rule
	Method string // HTTP Method
	Body   string

	IsPassGinContext   bool
	IsIgnoreShouldBind bool

	RequestImportPkgName string // e.g. userV1
	ReplyImportPkgName   string // e.g. userV1
	ProtoPkgName         string // e.g. userV1
}

ServiceMethod RPCMethod fields

func (*ServiceMethod) AddOne

func (t *ServiceMethod) AddOne(i int) int

AddOne counter

Jump to

Keyboard shortcuts

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