add swag && proto examples
This commit is contained in:
203
go/swag_example/docs/docs.go
Normal file
203
go/swag_example/docs/docs.go
Normal file
@@ -0,0 +1,203 @@
|
||||
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag
|
||||
package docs
|
||||
|
||||
import "github.com/swaggo/swag"
|
||||
|
||||
const docTemplate = `{
|
||||
"schemes": {{ marshal .Schemes }},
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "{{escape .Description}}",
|
||||
"title": "{{.Title}}",
|
||||
"termsOfService": "http://swagger.io/terms/",
|
||||
"contact": {
|
||||
"name": "API Support",
|
||||
"url": "http://www.swagger.io/support",
|
||||
"email": "support@swagger.io"
|
||||
},
|
||||
"license": {
|
||||
"name": "Apache 2.0",
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
},
|
||||
"version": "{{.Version}}"
|
||||
},
|
||||
"host": "{{.Host}}",
|
||||
"basePath": "{{.BasePath}}",
|
||||
"paths": {
|
||||
"/v2/object": {
|
||||
"get": {
|
||||
"description": "blabla...",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "get an object",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Some ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.Object"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "We need ID!!",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Can not find ID",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "blabla...",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "create an object.",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Add Object",
|
||||
"name": "object",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.Object"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.Object"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "We need ID!!",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Can not find ID",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v2/object/{id}": {
|
||||
"get": {
|
||||
"description": "get struct array by ID",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Offset",
|
||||
"name": "offset",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Offset",
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "We need ID!!",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Can not find ID",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"main.APIError": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorCode": {
|
||||
"type": "integer"
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"main.Object": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"description": "这是一个ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"description": "这是对象的名字",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
// SwaggerInfo holds exported Swagger Info so clients can modify it
|
||||
var SwaggerInfo = &swag.Spec{
|
||||
Version: "1.0",
|
||||
Host: "petstore.swagger.io:8080",
|
||||
BasePath: "/v2",
|
||||
Schemes: []string{},
|
||||
Title: "Swagger Example API",
|
||||
Description: "This is a sample server Petstore server.",
|
||||
InfoInstanceName: "swagger",
|
||||
SwaggerTemplate: docTemplate,
|
||||
}
|
||||
|
||||
func init() {
|
||||
swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo)
|
||||
}
|
||||
180
go/swag_example/docs/swagger.json
Normal file
180
go/swag_example/docs/swagger.json
Normal file
@@ -0,0 +1,180 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"description": "This is a sample server Petstore server.",
|
||||
"title": "Swagger Example API",
|
||||
"termsOfService": "http://swagger.io/terms/",
|
||||
"contact": {
|
||||
"name": "API Support",
|
||||
"url": "http://www.swagger.io/support",
|
||||
"email": "support@swagger.io"
|
||||
},
|
||||
"license": {
|
||||
"name": "Apache 2.0",
|
||||
"url": "http://www.apache.org/licenses/LICENSE-2.0.html"
|
||||
},
|
||||
"version": "1.0"
|
||||
},
|
||||
"host": "petstore.swagger.io:8080",
|
||||
"basePath": "/v2",
|
||||
"paths": {
|
||||
"/v2/object": {
|
||||
"get": {
|
||||
"description": "blabla...",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "get an object",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Some ID",
|
||||
"name": "id",
|
||||
"in": "path",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.Object"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "We need ID!!",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Can not find ID",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "blabla...",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"summary": "create an object.",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Add Object",
|
||||
"name": "object",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.Object"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.Object"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "We need ID!!",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Can not find ID",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v2/object/{id}": {
|
||||
"get": {
|
||||
"description": "get struct array by ID",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"parameters": [
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Offset",
|
||||
"name": "offset",
|
||||
"in": "query",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "Offset",
|
||||
"name": "limit",
|
||||
"in": "query",
|
||||
"required": true
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "ok",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "We need ID!!",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
},
|
||||
"404": {
|
||||
"description": "Can not find ID",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/main.APIError"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"main.APIError": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"createdAt": {
|
||||
"type": "string"
|
||||
},
|
||||
"errorCode": {
|
||||
"type": "integer"
|
||||
},
|
||||
"errorMessage": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"main.Object": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"id": {
|
||||
"description": "这是一个ID",
|
||||
"type": "integer"
|
||||
},
|
||||
"name": {
|
||||
"description": "这是对象的名字",
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
go/swag_example/docs/swagger.yaml
Normal file
120
go/swag_example/docs/swagger.yaml
Normal file
@@ -0,0 +1,120 @@
|
||||
basePath: /v2
|
||||
definitions:
|
||||
main.APIError:
|
||||
properties:
|
||||
createdAt:
|
||||
type: string
|
||||
errorCode:
|
||||
type: integer
|
||||
errorMessage:
|
||||
type: string
|
||||
type: object
|
||||
main.Object:
|
||||
properties:
|
||||
id:
|
||||
description: 这是一个ID
|
||||
type: integer
|
||||
name:
|
||||
description: 这是对象的名字
|
||||
type: string
|
||||
type: object
|
||||
host: petstore.swagger.io:8080
|
||||
info:
|
||||
contact:
|
||||
email: support@swagger.io
|
||||
name: API Support
|
||||
url: http://www.swagger.io/support
|
||||
description: This is a sample server Petstore server.
|
||||
license:
|
||||
name: Apache 2.0
|
||||
url: http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
termsOfService: http://swagger.io/terms/
|
||||
title: Swagger Example API
|
||||
version: "1.0"
|
||||
paths:
|
||||
/v2/object:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: blabla...
|
||||
parameters:
|
||||
- description: Some ID
|
||||
in: path
|
||||
name: id
|
||||
required: true
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: ok
|
||||
schema:
|
||||
$ref: '#/definitions/main.Object'
|
||||
"400":
|
||||
description: We need ID!!
|
||||
schema:
|
||||
$ref: '#/definitions/main.APIError'
|
||||
"404":
|
||||
description: Can not find ID
|
||||
schema:
|
||||
$ref: '#/definitions/main.APIError'
|
||||
summary: get an object
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: blabla...
|
||||
parameters:
|
||||
- description: Add Object
|
||||
in: body
|
||||
name: object
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/main.Object'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: ok
|
||||
schema:
|
||||
$ref: '#/definitions/main.Object'
|
||||
"400":
|
||||
description: We need ID!!
|
||||
schema:
|
||||
$ref: '#/definitions/main.APIError'
|
||||
"404":
|
||||
description: Can not find ID
|
||||
schema:
|
||||
$ref: '#/definitions/main.APIError'
|
||||
summary: create an object.
|
||||
/v2/object/{id}:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: get struct array by ID
|
||||
parameters:
|
||||
- description: Offset
|
||||
in: query
|
||||
name: offset
|
||||
required: true
|
||||
type: integer
|
||||
- description: Offset
|
||||
in: query
|
||||
name: limit
|
||||
required: true
|
||||
type: integer
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: ok
|
||||
schema:
|
||||
type: string
|
||||
"400":
|
||||
description: We need ID!!
|
||||
schema:
|
||||
$ref: '#/definitions/main.APIError'
|
||||
"404":
|
||||
description: Can not find ID
|
||||
schema:
|
||||
$ref: '#/definitions/main.APIError'
|
||||
swagger: "2.0"
|
||||
Reference in New Issue
Block a user