Skip to content

Latest commit

 

History

History
45 lines (37 loc) · 1.15 KB

README_zh.md

File metadata and controls

45 lines (37 loc) · 1.15 KB

SwaggerAPI

SwaggerAPI 是一个简单的 API,允许您为API创建SwaggerUI,为项目开发提供帮助。它基于Swagger 2.0规范。 通过读取进程中的grpc服务,自动生成swagger文档数据,同时提供swagger-ui服务,方便查看文档。

推荐使用gkit框架,可以自动生成swagger文档,同时提供swagger-ui服务。

本项目是gkit的需求衍生品,也可以单独使用。

Installation

$ go get github.com/ml444/swaggerapi

Usage

package main

import (
    "github.com/ml444/gkit/log"
    "github.com/ml444/gkit/transport/httpx"
    "github.com/ml444/swaggerapi"
)

func main() {
	var err error
	srv := httpx.NewServer(
		httpx.Timeout(time.Duration(hcfg.Timeout)*time.Millisecond),
		httpx.Address(hcfg.HTTPAddr),
	)
	// Create a new SwaggerAPI instance
	swaggerapi.RegisterAPI(srv)
	
	// Register your API handlers
	//userpb.RegisterServerWithHTTP(srv)
	
	if err = srv.Start(context.Background()); err != nil {
		log.Error(err.Error())
		return
	}
}
$ go run main.go

Visithttp://localhost:5050/swagger