parser

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GoTypeToSwagType added in v1.2.0

func GoTypeToSwagType(goType string) string

GoTypeToSwagType 将 Go 类型映射为 swaggo 类型字符串

func ToSnakeCase added in v1.2.0

func ToSnakeCase(s string) string

ToSnakeCase 将 CamelCase 转换为 snake_case

Types

type Method

type Method struct {
	Name       string
	Input      string
	Output     string
	Doc        string // 方法注释(原始文本)
	Summary    string // swag @Summary(取 Doc 第一行)
	Tags       string // swag @Tags(默认 = ServiceName)
	HTTPMethod string // swag @Router 方法(默认 POST)
	Route      string // swag @Router 路径(默认 /{lower(Name)})
}

Method 服务方法

type Model added in v1.1.0

type Model struct {
	Name        string       // struct 名称
	TableName   string       // 数据库表名(snake_case,可被 gorm tag 覆盖)
	Comment     string       // struct 注释
	Fields      []ModelField // 所有字段
	HasGormTags bool         // 是否含 gorm tag(用于判断是否需要生成 model 文件)
}

Model 从 IDL 解析出的 gorm Model 定义

type ModelField added in v1.1.0

type ModelField struct {
	Name       string // Go 字段名
	Type       string // Go 类型
	JSONTag    string // json tag 值
	GormTag    string // gorm tag 值
	Comment    string // 行注释
	IsPrimary  bool   // 是否主键
	IsAutoIncr bool   // 是否自增
	IsNotNull  bool   // 是否非空
	IsUnique   bool   // 是否唯一索引
	SwagType   string // swag 类型(integer/string/number/boolean/array/object)
	Example    string // swag 示例值
}

ModelField 模型字段(结构体字段)

type ParseResult added in v1.1.0

type ParseResult struct {
	PackageName string
	Services    []*Service
	Models      []*Model
	Source      SourceType
}

ParseResult 完整解析结果

func ParseFull added in v1.1.0

func ParseFull(idlPath string) (*ParseResult, error)

ParseFull 解析IDL文件,同时返回服务定义和模型定义

func ParseProto added in v1.2.0

func ParseProto(protoPath string) (*ParseResult, error)

ParseProto parses a .proto file into a ParseResult.

type Service

type Service struct {
	ServiceName string
	PackageName string
	Methods     []Method
	Title       string // swag @title(默认 = ServiceName + " API")
	Description string // swag @description(取接口注释)
}

Service 服务定义(接口)

func Parse

func Parse(idlPath string) (packageName string, services []*Service, err error)

Parse 解析IDL文件生成服务定义(向后兼容)

type SourceType added in v1.2.0

type SourceType string
const (
	SourceGo    SourceType = "go"
	SourceProto SourceType = "proto"
	SourceDB    SourceType = "db"
)

Jump to

Keyboard shortcuts

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