first commit
This commit is contained in:
3
example/generate.go
Normal file
3
example/generate.go
Normal file
@ -0,0 +1,3 @@
|
||||
package example
|
||||
|
||||
//go:generate goctl api plugin -plugin goctl-swagger="swagger" -api user.api -dir .
|
226
example/swagger.json
Normal file
226
example/swagger.json
Normal file
@ -0,0 +1,226 @@
|
||||
{
|
||||
"swagger": "2.0",
|
||||
"info": {
|
||||
"title": "",
|
||||
"version": ""
|
||||
},
|
||||
"schemes": [
|
||||
"http",
|
||||
"https"
|
||||
],
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"paths": {
|
||||
"/api/user/:id": {
|
||||
"get": {
|
||||
"summary": "获取用户信息",
|
||||
"operationId": "/api/user/:id",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/UserInfoReply"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/UserInfoReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"user-api"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/user/login": {
|
||||
"post": {
|
||||
"summary": "登录",
|
||||
"operationId": "/api/user/login",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {}
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"user-api"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/user/register": {
|
||||
"post": {
|
||||
"summary": "注册",
|
||||
"description": "注册一个用户",
|
||||
"operationId": "/api/user/register",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {}
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"user-api"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/api/user/search": {
|
||||
"get": {
|
||||
"summary": "用户搜索",
|
||||
"operationId": "/api/user/search",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/UserSearchReply"
|
||||
}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/UserSearchReq"
|
||||
}
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"user-api"
|
||||
]
|
||||
}
|
||||
},
|
||||
"/user/ping": {
|
||||
"get": {
|
||||
"operationId": "/user/ping",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "A successful response.",
|
||||
"schema": {}
|
||||
}
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"name": "body",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {}
|
||||
}
|
||||
],
|
||||
"tags": [
|
||||
"greet"
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"LoginReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Username": {
|
||||
"type": "string"
|
||||
},
|
||||
"Password": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "LoginReq"
|
||||
},
|
||||
"RegisterReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Username": {
|
||||
"type": "string"
|
||||
},
|
||||
"Password": {
|
||||
"type": "string"
|
||||
},
|
||||
"Mobile": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "RegisterReq"
|
||||
},
|
||||
"UserInfoReply": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Name": {
|
||||
"type": "string"
|
||||
},
|
||||
"Age": {
|
||||
"type": "integer",
|
||||
"format": "int32"
|
||||
},
|
||||
"Birthday": {
|
||||
"type": "string"
|
||||
},
|
||||
"Description": {
|
||||
"type": "string"
|
||||
},
|
||||
"Tag": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"title": "UserInfoReply"
|
||||
},
|
||||
"UserInfoReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"Id": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "UserInfoReq"
|
||||
},
|
||||
"UserSearchReply": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"KeyWord": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/UserInfoReply"
|
||||
}
|
||||
}
|
||||
},
|
||||
"title": "UserSearchReply"
|
||||
},
|
||||
"UserSearchReq": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"KeyWord": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"title": "UserSearchReq"
|
||||
}
|
||||
}
|
||||
}
|
79
example/user.api
Normal file
79
example/user.api
Normal file
@ -0,0 +1,79 @@
|
||||
info(
|
||||
title: "type title here"
|
||||
desc: "type desc here"
|
||||
author: "type author here"
|
||||
email: "type email here"
|
||||
version: "type version here"
|
||||
)
|
||||
|
||||
type (
|
||||
RegisterReq {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Mobile string `json:"mobile"`
|
||||
}
|
||||
// 登录请求
|
||||
LoginReq {
|
||||
// 用户名
|
||||
Username string `json:"username" desc:"用户名"`
|
||||
Password string `json:"password"` //密码
|
||||
} // 登录请求
|
||||
|
||||
UserInfoReq {
|
||||
Id string `path:"id"`
|
||||
}
|
||||
|
||||
UserInfoReply {
|
||||
Name string `json:"name"`
|
||||
Age int `json:"age"`
|
||||
Birthday string `json:"birthday"`
|
||||
Description string `json:"description"`
|
||||
Tag []string `json:"tag"`
|
||||
}
|
||||
|
||||
UserSearchReq {
|
||||
KeyWord string `form:"keyWord"`
|
||||
}
|
||||
|
||||
UserSearchReply {
|
||||
KeyWord []UserInfoReply
|
||||
}
|
||||
)
|
||||
|
||||
service user-api {
|
||||
@doc(
|
||||
summary: "注册"
|
||||
description: "注册一个用户"
|
||||
)
|
||||
@handler register
|
||||
post /api/user/register (RegisterReq)
|
||||
|
||||
@doc(
|
||||
summary: "登录"
|
||||
)
|
||||
@handler login
|
||||
post /api/user/login (LoginReq)
|
||||
|
||||
@doc(
|
||||
summary: "获取用户信息"
|
||||
)
|
||||
@handler getUserInfo
|
||||
get /api/user/:id (UserInfoReq) returns (UserInfoReply)
|
||||
|
||||
@doc(
|
||||
summary: "用户搜索"
|
||||
)
|
||||
@handler searchUser
|
||||
get /api/user/search (UserSearchReq) returns (UserSearchReply)
|
||||
}
|
||||
|
||||
@server(
|
||||
jwt: Auth
|
||||
group: greet
|
||||
middleware: LogHandler
|
||||
)
|
||||
service user-api {
|
||||
@handler ping
|
||||
get /user/ping
|
||||
}
|
||||
//goctl api plugin -plugin goctl-swagger -api user.api -dir .
|
Reference in New Issue
Block a user