internal

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ParamTypePath   string = "path"
	ParamTypeQuery  string = "query"
	ParamTypeHeader string = "header"
	ParamTypeCookie string = "cookie"
	ParamTypeBody   string = "body"
	ParamFormData   string = "formData"
)
View Source
const (
	DataTypeString string = "string"
	DataTypeNumber string = "number"
	DataTypeInt    string = "integer"
	DataTypeBool   string = "boolean"
	DataTypeArray  string = "array"
	DataTypeObject string = "object"
)
View Source
const (
	ZServiceTag     = "zService"
	ZReplyTypeTag   = "zResult"
	ZSummaryTag     = "zSummary"
	ZDescriptionTag = "zDescription"
	ZTagsTag        = "zTags"
	ZParamTag       = "zParam"
	ZReplyDataTag   = "zResultData"
	ZAcceptTag      = "zAccept"
	ZProduceTag     = "zProduce"
	ZRouterTag      = "zRouter"
)
View Source
const (
	SwaggerSummaryTag     = "@Summary"
	SwaggerDescriptionTag = "@Description"
	SwaggerTagsTag        = "@Tags"
	SwaggerParamTag       = "@Param"
	SwaggerSuccessTag     = "@Success"
	SwaggerFailureTag     = "@Failure"
	SwaggerAcceptTag      = "@Accept"
	SwaggerProduceTag     = "@Produce"
	SwaggerRouterTag      = "@Router"
)
View Source
const DefaultErrorCode = "500"

Variables

This section is empty.

Functions

func GenerateCode

func GenerateCode(path string, serviceDesc *ServiceDesc) error

func Ternary

func Ternary[T any](a bool, b, c T) T

Ternary 三目运算

func TypeConvert

func TypeConvert(strValue string, dataType string, ptr bool) (value interface{}, err error)

func TypeConvertBool

func TypeConvertBool(strValue string) (value bool, err error)

func TypeConvertBoolPtr

func TypeConvertBoolPtr(strValue string) (value *bool, err error)

func TypeConvertFloat32

func TypeConvertFloat32(strValue string) (value float32, err error)

func TypeConvertFloat32Ptr

func TypeConvertFloat32Ptr(strValue string) (value *float32, err error)

func TypeConvertFloat64

func TypeConvertFloat64(strValue string) (value float64, err error)

func TypeConvertFloat64Ptr

func TypeConvertFloat64Ptr(strValue string) (value *float64, err error)

func TypeConvertInt

func TypeConvertInt(strValue string) (value int, err error)

func TypeConvertInt16

func TypeConvertInt16(strValue string) (value int16, err error)

func TypeConvertInt16Ptr

func TypeConvertInt16Ptr(strValue string) (value *int16, err error)

func TypeConvertInt32

func TypeConvertInt32(strValue string) (value int32, err error)

func TypeConvertInt32Ptr

func TypeConvertInt32Ptr(strValue string) (value *int32, err error)

func TypeConvertInt64

func TypeConvertInt64(strValue string) (value int64, err error)

func TypeConvertInt64Ptr

func TypeConvertInt64Ptr(strValue string) (value *int64, err error)

func TypeConvertInt8

func TypeConvertInt8(strValue string) (value int8, err error)

func TypeConvertInt8Ptr

func TypeConvertInt8Ptr(strValue string) (value *int8, err error)

func TypeConvertIntPtr

func TypeConvertIntPtr(strValue string) (value *int, err error)

func TypeConvertUInt

func TypeConvertUInt(strValue string) (value uint, err error)

func TypeConvertUInt16

func TypeConvertUInt16(strValue string) (value uint16, err error)

func TypeConvertUInt16Ptr

func TypeConvertUInt16Ptr(strValue string) (value *uint16, err error)

func TypeConvertUInt32

func TypeConvertUInt32(strValue string) (value uint32, err error)

func TypeConvertUInt32Ptr

func TypeConvertUInt32Ptr(strValue string) (value *uint32, err error)

func TypeConvertUInt64

func TypeConvertUInt64(strValue string) (value uint64, err error)

func TypeConvertUInt64Ptr

func TypeConvertUInt64Ptr(strValue string) (value *uint64, err error)

func TypeConvertUInt8

func TypeConvertUInt8(strValue string) (value uint8, err error)

func TypeConvertUInt8Ptr

func TypeConvertUInt8Ptr(strValue string) (value *uint8, err error)

func TypeConvertUIntPtr

func TypeConvertUIntPtr(strValue string) (value *uint, err error)

Types

type AcceptCommentParser

type AcceptCommentParser struct{}

func (*AcceptCommentParser) Parse

func (a *AcceptCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

type Config

type Config struct {
	// service文件所在目录 必传
	ServicePath string `yaml:"servicePath"`

	// 要生成的控制器代码文件所在目录 必传
	HandlePath string `yaml:"handlePath"`

	// 接口返回结果的类型 必传
	ResultType string `yaml:"result"`

	// 默认的错误代码
	ErrorCode int `yaml:"errorCode"`

	// 需要额外导入的包
	Imports []string `yaml:"imports"`

	// 自定义属性,必须以x开头
	CustomAnnotations []string `yaml:"customAnnotations"`
}

func LoadConfig

func LoadConfig(configFile string) (config *Config, err error)

type CustomCommentParser

type CustomCommentParser struct{}

func (*CustomCommentParser) Parse

func (c *CustomCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

type DefaultCommentParser

type DefaultCommentParser struct{}

func (*DefaultCommentParser) Parse

func (d *DefaultCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

type DescriptionCommentParser

type DescriptionCommentParser struct{}

func (*DescriptionCommentParser) Parse

func (d *DescriptionCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

type MethodCommentParser

type MethodCommentParser interface {
	Parse(annotation *go_annotation.Annotation, method *MethodDesc) error
}

func GetMethodCommentParser

func GetMethodCommentParser(annotation *go_annotation.Annotation) MethodCommentParser

type MethodDesc

type MethodDesc struct {
	go_annotation.MethodDesc
	ErrorCode         string               // 错误编码
	Path              string               // url
	Method            string               // 全小写
	Params            []*MethodParam       // 参数
	Result            *go_annotation.Field // 返回值
	Summary           string
	Description       string
	Tags              string
	Accept            string
	Produce           string                               // 返回的数据格式 默认为json
	ApiResultType     string                               // 接口返回值类型 不含指针
	ApiResultDataType string                               // 接口返回值Data类型 不含指针
	CustomAnnotations map[string]*go_annotation.Annotation //自定义注解
}

type MethodParam

type MethodParam struct {
	go_annotation.Field
	ParamType     string
	ParamDataType string
	Required      bool
	Desc          string
}

type MethodParser

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

func NewMethodParser

func NewMethodParser(funcDecl *go_annotation.MethodDesc) *MethodParser

func (*MethodParser) Parse

func (m *MethodParser) Parse(resultType string, errorCode string) (method *MethodDesc, err error)

type ParamParser

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

func NewParamParser

func NewParamParser(funcDecl *go_annotation.MethodDesc) *ParamParser

func (*ParamParser) Parse

func (p *ParamParser) Parse() (params []*MethodParam, err error)

type ProduceCommentParser

type ProduceCommentParser struct{}

func (*ProduceCommentParser) Parse

func (p *ProduceCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

type ReplyDataCommentParser

type ReplyDataCommentParser struct{}

func (*ReplyDataCommentParser) Parse

func (r *ReplyDataCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

type ReplyTypeCommentParser

type ReplyTypeCommentParser struct{}

func (*ReplyTypeCommentParser) Parse

func (r *ReplyTypeCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

type RouterCommentParser

type RouterCommentParser struct{}

func (*RouterCommentParser) Parse

func (r *RouterCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

type ServiceDesc

type ServiceDesc struct {
	Name         string                               // 结构体名
	PackageName  string                               // 包名
	Imports      map[string]*go_annotation.ImportDesc // 导入信息
	ExtraImports []string                             // 额外导入包
	Comments     []string                             // 注释
	Annotations  map[string]*go_annotation.Annotation // 注解
	//Fields      []*Field               // 字段 暂不支持
	Methods     []*MethodDesc // 方法
	Description string        // 描述
	ReplyType   string        // 接口返回值类型
}

func ParseServiceDesc

func ParseServiceDesc(fileDescList []*go_annotation.FileDesc, imports []string, resultType string, errorCode string) ([]*ServiceDesc, error)

type ServiceParser

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

func NewServiceParser

func NewServiceParser(genDecl *go_annotation.StructDesc) *ServiceParser

func (*ServiceParser) Parse

func (s *ServiceParser) Parse(resultType string, errorCode string, imports []string) (sDesc *ServiceDesc, err error)

type SummaryCommentParser

type SummaryCommentParser struct{}

func (*SummaryCommentParser) Parse

func (s *SummaryCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

type TagsCommentParser

type TagsCommentParser struct{}

func (*TagsCommentParser) Parse

func (t *TagsCommentParser) Parse(annotation *go_annotation.Annotation, method *MethodDesc) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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