Skip to content

Commit

Permalink
Merge pull request #116 from LucienShui/chore/status_to_code
Browse files Browse the repository at this point in the history
change response status to response code, rewrite error response
  • Loading branch information
LucienShui authored Sep 30, 2021
2 parents 0d1340f + 83f8c51 commit 1491f53
Show file tree
Hide file tree
Showing 21 changed files with 547 additions and 127 deletions.
4 changes: 2 additions & 2 deletions config/config.go → common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package config

import (
"encoding/json"
"github.com/PasteUs/PasteMeGoBackend/flag"
"github.com/PasteUs/PasteMeGoBackend/logging"
"github.com/PasteUs/PasteMeGoBackend/common/flag"
"github.com/PasteUs/PasteMeGoBackend/common/logging"
"go.uber.org/zap"
"io/ioutil"
"os"
Expand Down
4 changes: 2 additions & 2 deletions config/meta.go → common/config/meta.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package config

import (
"github.com/PasteUs/PasteMeGoBackend/logging"
"github.com/PasteUs/PasteMeGoBackend/common/logging"
"go.uber.org/zap"
)

var version = "3.4.1"
var version = "3.5.0"
var validConfigVersion = []string{"3.3.0", ""}

func init() {
Expand Down
2 changes: 1 addition & 1 deletion flag/flag.go → common/flag/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package flag

import (
"flag"
"github.com/PasteUs/PasteMeGoBackend/logging"
"github.com/PasteUs/PasteMeGoBackend/common/logging"
"go.uber.org/zap"
"os"
"strings"
Expand Down
File renamed without changes.
File renamed without changes.
238 changes: 238 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
{
"swagger": "2.0",
"info": {
"description": "PasteMe Go Backend API",
"title": "PasteMe API",
"termsOfService": "https://github.com/LucienShui/PasteMe#%E5%85%8D%E8%B4%A3%E5%A3%B0%E6%98%8E",
"contact": {
"name": "Lucien",
"url": "https://blog.lucien.ink",
"email": "[email protected]"
},
"license": {
"name": "GNU General Public License v3.0",
"url": "https://github.com/PasteUs/PasteMeGoBackend/blob/main/LICENSE"
},
"version": "3.4.1"
},
"basePath": "/api/v3",
"paths": {
"/": {
"get": {
"description": "心跳检测",
"produces": [
"application/json"
],
"tags": [
"Common"
],
"summary": "心跳检测",
"parameters": [
{
"enum": [
"\"beat\""
],
"type": "string",
"description": "方法",
"name": "method",
"in": "query",
"required": true
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/common.Response"
}
},
"default": {
"description": "",
"schema": {
"$ref": "#/definitions/common.ErrorResponse"
}
}
}
}
},
"/paste/": {
"post": {
"description": "只有在登陆的状态下才能创建永久的一贴",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Paste"
],
"summary": "创建永久存储或者是自我销毁的一贴",
"parameters": [
{
"type": "string",
"description": "登陆的 Token",
"name": "Authorization",
"in": "header"
},
{
"description": "请求数据",
"name": "data",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/paste.CreateRequest"
}
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/paste.CreateResponse"
}
},
"default": {
"description": "",
"schema": {
"$ref": "#/definitions/common.ErrorResponse"
}
}
}
}
},
"/paste/{key}": {
"get": {
"description": "如果不指定 Accept: application/json 的话,默认会返回 text/plain 格式的 content",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"Paste"
],
"summary": "读取一贴",
"parameters": [
{
"type": "string",
"default": "\"text/plain\"",
"description": "响应格式",
"name": "Accept",
"in": "header"
},
{
"type": "string",
"description": "索引",
"name": "key",
"in": "path",
"required": true
}
],
"responses": {
"201": {
"description": "Created",
"schema": {
"$ref": "#/definitions/paste.GetResponse"
}
},
"default": {
"description": "",
"schema": {
"$ref": "#/definitions/common.ErrorResponse"
}
}
}
}
}
},
"definitions": {
"common.ErrorResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 200
},
"message": {
"type": "string",
"example": "ok"
}
}
},
"common.Response": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 200
}
}
},
"paste.CreateRequest": {
"type": "object",
"properties": {
"content": {
"description": "内容,最大长度为 16777215(2^24-1) 个字符",
"type": "string",
"example": "Hello World!"
},
"expire_count": {
"description": "访问若干次后自我销毁",
"type": "integer",
"example": 1
},
"expire_minute": {
"description": "创建若干分钟后自我销毁",
"type": "integer",
"example": 5
},
"lang": {
"description": "语言类型",
"type": "string",
"example": "plain"
},
"password": {
"description": "密码",
"type": "string"
},
"self_destruct": {
"description": "是否自我销毁",
"type": "boolean",
"example": true
}
}
},
"paste.CreateResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 200
},
"key": {
"type": "string",
"example": "a1b2c3d4"
}
}
},
"paste.GetResponse": {
"type": "object",
"properties": {
"code": {
"type": "integer",
"example": 200
},
"content": {
"type": "string",
"example": "Hello World!"
},
"lang": {
"type": "string",
"example": "plain"
}
}
}
}
}
Loading

0 comments on commit 1491f53

Please sign in to comment.