Skip to content

Commit 2736f7a

Browse files
committed
api骨架
1 parent 1e5dc4b commit 2736f7a

33 files changed

Lines changed: 1345 additions & 33 deletions

File tree

.dockerignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
.*
3+
4+
config.yaml
5+
6+
*.zip
7+
*.exe
8+
9+
scriptcat
10+
cloudcat
11+
12+
cloudcat.db

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11

2-
.idea
3-
.vscode
2+
.*
43

54
config.yaml
65

76
*.zip
87
*.exe
98

109
scriptcat
11-
cloudcat
10+
cloudcat
11+
12+
cloudcat.db

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ VERSION=0.1.0
22
DOCKER_REPO=codfrm
33
REMOTE_REPO=$(DOCKER_REPO)/cloudcat:$(VERSION)
44

5-
build: scriptcat cloudcat
5+
build: swagger scriptcat cloudcat
66

77
scriptcat:
88
go build .\cmd\scriptcat
@@ -19,3 +19,6 @@ docker-test:
1919
docker-push: docker
2020
docker tag cloudcat $(REMOTE_REPO)
2121
docker push $(REMOTE_REPO)
22+
23+
swagger:
24+
swag init -g internal/interface/http/apiv1/router.go

cmd/app/main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package main
2+
3+
import (
4+
"github.com/scriptscat/cloudcat/internal/app"
5+
"github.com/scriptscat/cloudcat/internal/pkg/config"
6+
"github.com/sirupsen/logrus"
7+
)
8+
9+
func main() {
10+
cfg, err := config.Init("config.yaml")
11+
if err != nil {
12+
logrus.Fatalln(err)
13+
}
14+
15+
if err := app.Run(cfg); err != nil {
16+
logrus.Fatalf("app start err: %v", err)
17+
}
18+
}

cmd/cloudcat/main.go

Lines changed: 0 additions & 5 deletions
This file was deleted.

config.yaml.example

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,42 @@
1-
21
# 启动模式 debug/prod
32
mode: debug
43

5-
db:
6-
mysql:
7-
dsn: root:password@tcp(127.0.0.1:3306)/scriptweb?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local&multiStatements=true
8-
prefix: cm_
9-
10-
redis:
11-
addr: localhost:6379
12-
password:
13-
db: 0
4+
database:
5+
type: mysql
6+
mysql:
7+
dsn: root:password@tcp(127.0.0.1:3306)/cloudcat?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local&multiStatements=true
8+
prefix: cat_
9+
# sqlite:
10+
# file: cloudcat.db
11+
12+
kvDb:
13+
type: redis
14+
redis:
15+
addr: localhost:6379
16+
password:
17+
db: 0
18+
# sqlite:
19+
# file: cloudcat.db
1420

1521
# 缓存redis
1622
cache:
17-
addr: localhost:6379
18-
password:
19-
db: 1
23+
type: redis
24+
redis:
25+
addr: localhost:6379
26+
password:
27+
db: 1
28+
# sqlite:
29+
# file: cloudcat.db
2030

21-
# 暴露的端口
22-
webPort: 8080
31+
# 监听地址
32+
addr: :8080
2333

2434
# 论坛的oauth2登录
2535
oauth:
26-
clientId: xxx
27-
clientSecret: xxx
36+
bbs:
37+
clientId: xxx
38+
clientSecret: xxx
2839

2940
# jwt token
3041
jwt:
3142
token: xxx
32-
33-
# 执行的定时任务
34-
crontab:
35-
- scripts

docs/docs.go

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
// Package docs GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
2+
// This file was generated by swaggo/swag
3+
package docs
4+
5+
import (
6+
"bytes"
7+
"encoding/json"
8+
"strings"
9+
"text/template"
10+
11+
"github.com/swaggo/swag"
12+
)
13+
14+
var doc = `{
15+
"schemes": {{ marshal .Schemes }},
16+
"swagger": "2.0",
17+
"info": {
18+
"description": "{{escape .Description}}",
19+
"title": "{{.Title}}",
20+
"contact": {},
21+
"version": "{{.Version}}"
22+
},
23+
"host": "{{.Host}}",
24+
"basePath": "{{.BasePath}}",
25+
"paths": {
26+
"/system/version": {
27+
"get": {
28+
"description": "查询脚本猫版本信息",
29+
"consumes": [
30+
"application/json"
31+
],
32+
"produces": [
33+
"application/json"
34+
],
35+
"tags": [
36+
"system"
37+
],
38+
"summary": "系统",
39+
"operationId": "system",
40+
"responses": {
41+
"200": {
42+
"description": "OK",
43+
"schema": {
44+
"$ref": "#/definitions/repository.ScriptCatInfo"
45+
}
46+
},
47+
"400": {
48+
"description": "Bad Request",
49+
"schema": {
50+
"$ref": "#/definitions/errs.JsonRespondError"
51+
}
52+
}
53+
}
54+
}
55+
}
56+
},
57+
"definitions": {
58+
"errs.JsonRespondError": {
59+
"type": "object",
60+
"properties": {
61+
"code": {
62+
"type": "integer"
63+
},
64+
"msg": {
65+
"type": "string"
66+
}
67+
}
68+
},
69+
"repository.ScriptCatInfo": {
70+
"type": "object",
71+
"properties": {
72+
"message": {
73+
"type": "string"
74+
},
75+
"version": {
76+
"type": "string"
77+
}
78+
}
79+
}
80+
}
81+
}`
82+
83+
type swaggerInfo struct {
84+
Version string
85+
Host string
86+
BasePath string
87+
Schemes []string
88+
Title string
89+
Description string
90+
}
91+
92+
// SwaggerInfo holds exported Swagger Info so clients can modify it
93+
var SwaggerInfo = swaggerInfo{
94+
Version: "1.0",
95+
Host: "localhost:8080",
96+
BasePath: "/api/v1",
97+
Schemes: []string{},
98+
Title: "云猫api文档",
99+
Description: "",
100+
}
101+
102+
type s struct{}
103+
104+
func (s *s) ReadDoc() string {
105+
sInfo := SwaggerInfo
106+
sInfo.Description = strings.Replace(sInfo.Description, "\n", "\\n", -1)
107+
108+
t, err := template.New("swagger_info").Funcs(template.FuncMap{
109+
"marshal": func(v interface{}) string {
110+
a, _ := json.Marshal(v)
111+
return string(a)
112+
},
113+
"escape": func(v interface{}) string {
114+
// escape tabs
115+
str := strings.Replace(v.(string), "\t", "\\t", -1)
116+
// replace " with \", and if that results in \\", replace that with \\\"
117+
str = strings.Replace(str, "\"", "\\\"", -1)
118+
return strings.Replace(str, "\\\\\"", "\\\\\\\"", -1)
119+
},
120+
}).Parse(doc)
121+
if err != nil {
122+
return doc
123+
}
124+
125+
var tpl bytes.Buffer
126+
if err := t.Execute(&tpl, sInfo); err != nil {
127+
return doc
128+
}
129+
130+
return tpl.String()
131+
}
132+
133+
func init() {
134+
swag.Register(swag.Name, &s{})
135+
}

docs/swagger.json

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"swagger": "2.0",
3+
"info": {
4+
"title": "云猫api文档",
5+
"contact": {},
6+
"version": "1.0"
7+
},
8+
"host": "localhost:8080",
9+
"basePath": "/api/v1",
10+
"paths": {
11+
"/system/version": {
12+
"get": {
13+
"description": "查询脚本猫版本信息",
14+
"consumes": [
15+
"application/json"
16+
],
17+
"produces": [
18+
"application/json"
19+
],
20+
"tags": [
21+
"system"
22+
],
23+
"summary": "系统",
24+
"operationId": "system",
25+
"responses": {
26+
"200": {
27+
"description": "OK",
28+
"schema": {
29+
"$ref": "#/definitions/repository.ScriptCatInfo"
30+
}
31+
},
32+
"400": {
33+
"description": "Bad Request",
34+
"schema": {
35+
"$ref": "#/definitions/errs.JsonRespondError"
36+
}
37+
}
38+
}
39+
}
40+
}
41+
},
42+
"definitions": {
43+
"errs.JsonRespondError": {
44+
"type": "object",
45+
"properties": {
46+
"code": {
47+
"type": "integer"
48+
},
49+
"msg": {
50+
"type": "string"
51+
}
52+
}
53+
},
54+
"repository.ScriptCatInfo": {
55+
"type": "object",
56+
"properties": {
57+
"message": {
58+
"type": "string"
59+
},
60+
"version": {
61+
"type": "string"
62+
}
63+
}
64+
}
65+
}
66+
}

docs/swagger.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
basePath: /api/v1
2+
definitions:
3+
errs.JsonRespondError:
4+
properties:
5+
code:
6+
type: integer
7+
msg:
8+
type: string
9+
type: object
10+
repository.ScriptCatInfo:
11+
properties:
12+
message:
13+
type: string
14+
version:
15+
type: string
16+
type: object
17+
host: localhost:8080
18+
info:
19+
contact: {}
20+
title: 云猫api文档
21+
version: "1.0"
22+
paths:
23+
/system/version:
24+
get:
25+
consumes:
26+
- application/json
27+
description: 查询脚本猫版本信息
28+
operationId: system
29+
produces:
30+
- application/json
31+
responses:
32+
"200":
33+
description: OK
34+
schema:
35+
$ref: '#/definitions/repository.ScriptCatInfo'
36+
"400":
37+
description: Bad Request
38+
schema:
39+
$ref: '#/definitions/errs.JsonRespondError'
40+
summary: 系统
41+
tags:
42+
- system
43+
swagger: "2.0"

0 commit comments

Comments
 (0)