Skip to content

Commit a3c4ae1

Browse files
committed
feat: add api for wip/commit
1 parent 8e8b6e0 commit a3c4ae1

File tree

16 files changed

+2539
-126
lines changed

16 files changed

+2539
-126
lines changed

api/api_impl/impl.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ type APIController struct {
1414
controller.VersionController
1515
controller.ObjectController
1616
controller.UserController
17+
controller.WipController
18+
controller.CommitController
1719
}

api/custom_response.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ type JiaozifsResponse struct {
99
http.ResponseWriter
1010
}
1111

12-
func (response *JiaozifsResponse) JSON(v interface{}) {
12+
func (response *JiaozifsResponse) JSON(v interface{}, code ...int) {
1313
response.Header().Set("Content-Type", "application/json")
14-
response.WriteHeader(http.StatusOK)
14+
if len(code) == 0 {
15+
response.WriteHeader(http.StatusOK)
16+
} else {
17+
response.WriteHeader(code[0])
18+
}
19+
1520
err := json.NewEncoder(response).Encode(v)
1621
if err != nil {
1722
response.Error(err)
@@ -23,21 +28,25 @@ func (response *JiaozifsResponse) OK() {
2328
response.WriteHeader(http.StatusOK)
2429
}
2530

31+
func (response *JiaozifsResponse) NotFound() {
32+
response.WriteHeader(http.StatusNotFound)
33+
}
34+
2635
func (response *JiaozifsResponse) Error(err error) {
2736
response.WriteHeader(http.StatusInternalServerError)
2837
_, _ = response.Write([]byte(err.Error()))
2938
}
3039

31-
func (response *JiaozifsResponse) String(msg string) {
40+
func (response *JiaozifsResponse) String(msg string, code ...int) {
41+
if len(code) == 0 {
42+
response.WriteHeader(http.StatusOK)
43+
} else {
44+
response.WriteHeader(code[0])
45+
}
3246
response.Header().Set("Content-Type", "text/plain;charset=UTF-8")
33-
response.WriteHeader(http.StatusOK)
3447
_, _ = response.Write([]byte(msg))
3548
}
3649

37-
func (response *JiaozifsResponse) CodeMsg(code int, msg string) {
38-
response.WriteHeader(code)
39-
_, _ = response.Write([]byte(msg))
40-
}
4150
func (response *JiaozifsResponse) Code(code int) {
4251
response.WriteHeader(code)
4352
}

0 commit comments

Comments
 (0)