Categorygithub.com/ml444/swaggerapi
repositorypackage
0.0.0-20240519125347-d5de82d48588
Repository: https://github.com/ml444/swaggerapi.git
Documentation: pkg.go.dev

# Packages

No description provided by the author

# README

SwaggerAPI

SwaggerAPI is a simple API that allows you to create SwaggerUI for the API to help project development. It is based onSwagger 2.0 Specification

By reading the grpc service in the process, swagger document data is automatically generated, and the swagger-ui service is provided to facilitate document viewing.

It is recommended to use the gkit framework, which can automatically generate swagger documents and provide swagger-ui services.

This project is a demand derivative of gkit and can also be used independently.

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

访问:http://localhost:5050/swagger