apidoc

package
v0.0.0-...-49cc056 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2024 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(app *pine.Application, config *Config) pine.Handler

func SetApiEntity

func SetApiEntity(ctx *pine.Context, entity *Entity, configures ...Configure)

SetApiEntity 设置接口实体信息

Types

type Config

type Config struct {
	RoutePrefix   string      `json:"route_prefix"`
	Enable        bool        `json:"enable"`         // 是否启用apidoc
	DataPath      string      `json:"-"`              // 配置数据存储目录
	ResponseParam interface{} `json:"-"`              // 用于反射返回值信息
	Title         string      `json:"title"`          // 标题目录
	Desc          string      `json:"desc"`           // 描述
	Copyright     string      `json:"copyright"`      // 版权
	DefaultAuthor string      `json:"default_author"` // 默认作者
	Apps          []apiApp    `json:"apps"`           // 应用, 例如 前端接口,后端接口
	Groups        []apiGroup  `json:"groups"`         //  应用分组
	Cache         struct {
		Enable bool   `json:"enable"`
		Path   string `json:"path"`
		Reload bool   `json:"reload"`
		Max    int    `json:"max"`
	} `json:"cache"`
	Auth struct {
		Enable    bool   `json:"enable"`
		SecretKey string `json:"secret_key"`
	} `json:"auth"`
	FilterMethod []interface{}       `json:"filter_method"`
	Headers      []apiHeader         `json:"headers"` // 猜测是保存的公共头部
	Parameters   []interface{}       `json:"parameters"`
	Responses    []apiPublicResponse `json:"responses"`
	Docs         struct {
		MenuTitle string `json:"menu_title"`
		Menus     []struct {
			Title string `json:"title"`
			Path  string `json:"path,omitempty"`
			Items []struct {
				Title string `json:"title"`
				Path  string `json:"path"`
			} `json:"items,omitempty"`
		} `json:"menus"`
	} `json:"docs"`
	Crud struct {
		Controller struct {
			Path     string `json:"path"`
			Template string `json:"template"`
		} `json:"controller"`
		Service struct {
			Path     string `json:"path"`
			Template string `json:"template"`
		} `json:"service"`
		Model struct {
			Path          string `json:"path"`
			Template      string `json:"template"`
			DefaultFields []struct {
				Field       string `json:"field"`
				Desc        string `json:"desc"`
				Type        string `json:"type"`
				Length      int    `json:"length"`
				Default     string `json:"default"`
				NotNull     bool   `json:"not_null"`
				MainKey     bool   `json:"main_key"`
				Incremental bool   `json:"incremental"`
				Validate    string `json:"validate"`
				Query       bool   `json:"query"`
				List        bool   `json:"list"`
				Detail      bool   `json:"detail"`
				Add         bool   `json:"add"`
				Edit        bool   `json:"edit"`
			} `json:"default_fields"`
			FieldsTypes []string `json:"fields_types"`
		} `json:"model"`
		Validate struct {
			Path     string `json:"path"`
			Template string `json:"template"`
			Rules    []struct {
				Name    string `json:"name"`
				Rule    string `json:"rule"`
				Message string `json:"message"`
			} `json:"rules"`
		} `json:"validate"`
	} `json:"crud"`
	Debug bool `json:"debug"`
}

func DefaultConfig

func DefaultConfig() *Config

type Configure

type Configure func(entity *apiEntity)

func WithExcludeParams

func WithExcludeParams(excludeParams []string) Configure

WithExcludeParams 排除部分参数

func WithHeaders

func WithHeaders(headers []apiHeader) Configure

func WithImmutable

func WithImmutable(immutable bool) Configure

func WithNoParams

func WithNoParams() Configure

WithNoParams 不带参数

func WithOnlyParams

func WithOnlyParams(onlyParams []string) Configure

WithOnlyParams 只允许部分参数体现在文档内

type DemoParams

type DemoParams struct {
	Page int `json:"page" api:"require:true,remark:分页数,default:0"`
}

type DemoResponseParam

type DemoResponseParam struct {
	Code    int         `json:"code" api:"require:true,remark:状态码,default:0"`
	Message string      `json:"message" api:"require:true,remark:操作描述"`
	Data    interface{} `json:"data" api:"require:true,remark:业务数据"`
}

type Entity

type Entity struct {
	Title    string      // 标题
	Desc     string      // 描述
	ApiParam interface{} // 参数
	AppId    string      // 应用id
	Group    string      // 分组名称
	SubGroup string      // 子分组名称
	Tag      []string    // 标签
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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