Browse Source

完成api文档

yjp 10 months ago
parent
commit
054204e236
3 changed files with 21 additions and 4 deletions
  1. 1 1
      baize.go
  2. 6 3
      framework/core/api/options.go
  3. 14 0
      framework/core/api/router.go

+ 1 - 1
baize.go

@@ -11,7 +11,7 @@ func NewApplication(conf application.Config) *application.App {
 	apiConfig := conf.ApiConfig
 	apiInstance := api.New(api.WithUrlPrefix(apiConfig.UrlPrefix),
 		api.WithPort(apiConfig.Port),
-		api.WithSkipPaths(apiConfig.LogSkipPaths...))
+		api.WithLogSkipPaths(apiConfig.LogSkipPaths...))
 
 	// 创建基础设施
 	infrastructureConfig := new(infrastructure.Config)

+ 6 - 3
framework/core/api/options.go

@@ -8,7 +8,7 @@ type Options struct {
 	port string
 
 	// 日志跳过的打印路径
-	skipPaths []string
+	logSkipPaths []string
 }
 
 func (options Options) GetPort() string {
@@ -21,20 +21,23 @@ func (options Options) GetUrlPrefix() string {
 
 type Option func(options *Options)
 
+// WithUrlPrefix 设置URL前缀
 func WithUrlPrefix(urlPrefix string) Option {
 	return func(options *Options) {
 		options.urlPrefix = urlPrefix
 	}
 }
 
+// WithPort 设置端口
 func WithPort(port string) Option {
 	return func(options *Options) {
 		options.port = port
 	}
 }
 
-func WithSkipPaths(skipPaths ...string) Option {
+// WithLogSkipPaths 设置日志跳过的打印路径
+func WithLogSkipPaths(logSkipPaths ...string) Option {
 	return func(options *Options) {
-		options.skipPaths = skipPaths
+		options.logSkipPaths = logSkipPaths
 	}
 }

+ 14 - 0
framework/core/api/router.go

@@ -8,13 +8,27 @@ import (
 // Handler 请求处理函数
 type Handler func(c *Context)
 
+// Router 路由接口
 type Router interface {
+	// AddMiddlewares 添加中间件
 	AddMiddlewares(middlewares ...Handler) Router
+
+	// RegisterVersionedRouter 注册版本路由
 	RegisterVersionedRouter(version string, middlewares ...Handler) Router
+
+	// VersionedRouter 获取版本路由
 	VersionedRouter(version string) Router
+
+	// AddRoute 添加路由路径
 	AddRoute(method string, relativePath string, handlers ...Handler) Router
+
+	// Static 静态路由(指向目录)
 	Static(relativePath string, root string)
+
+	// StaticFile 静态路由(指向文件)
 	StaticFile(relativePath string, filepath string)
+
+	// BasePath 路由的基础路径,即去掉http://ip:port之后的URL部分(不包括AddRoute的RelativePath)
 	BasePath() string
 }