申請固定IP網站
程式語言學習筆記
css
文字框CSS
導覽列JS
Go Time
var startTime time.Time
startTime, err = time.Parse("2006-01-02 15:04:05", "2019-03-07 10:14:35")
startTimeStr := startTime.Format("2006-01-02 15:04:05")
Gin-swagger
建立文檔網站用套件。搭配gin。
get
import
生成文檔用的套件
get swagger cmd
建立文檔,需在main.go路徑執行。
生成的yaml檔
- test tag
swagger: "2.0"
在啟動程式後,透過網址開啟文檔。
http://localhost:1234/swagger/index.html
註解文檔
gin-swagger連結
get
import
生成文檔用的套件
get swagger cmd
建立文檔,需在main.go路徑執行。
import (
_ "chatservice/docs" // 加這行才能在網頁顯示文檔
"github.com/gin-gonic/gin"
ginSwagger "github.com/swaggo/gin-swagger"
"github.com/swaggo/gin-swagger/swaggerFiles"
)
// @Title blogger
// @Version 1.0.0
// @Description blog example
// @Host localhost:1234
// @BasePath /api
func main() {
router := gin.Default()
router.POST("/api/post/test", Test)
router.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
router.Run("localhost:1234")
}
// Test for demo
// @Summary test method
// @Description test for test
// @Tags test tag
// @Tags test tag
// @Accept application/x-www-form-urlencoded
// @Produce json
// @Param Param1 formData string true "string parameter" default(stringValue)
// @Success 200 {string} string "成功"
// @Failure 500 {string} string "内部错误"
// @Router /post/test [post]
func Test(c *gin.Context) {
p1String := c.PostForm("Param1")
生成的yaml檔
basePath: /api
host: localhost:1234
info:
contact: {}
description: blog example
license: {}
title: blogger
version: 1.0.0
paths:
/post/test:
post:
consumes:
- application/x-www-form-urlencoded
description: test for test
parameters:
- default: stringValue
description: string parameter
in: formData
name: Param1
required: true
type: string
produces:
- application/json
responses:
"200":
description: 成功
schema:
type: string
"500":
description: 内部错误
schema:
type: string
summary: test method
tags:
swagger: "2.0"
在啟動程式後,透過網址開啟文檔。
http://localhost:1234/swagger/index.html
註解文檔
gin-swagger連結
訂閱:
文章 (Atom)