forked from free-lancers/electricity_bill_calc_service
		
	feat(foundation):构建基本的路由创建结构。
This commit is contained in:
		
							
								
								
									
										28
									
								
								response/base-response.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								response/base-response.go
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,28 @@ | ||||
| package response | ||||
|  | ||||
| import ( | ||||
| 	"net/http" | ||||
|  | ||||
| 	"github.com/gin-gonic/gin" | ||||
| ) | ||||
|  | ||||
| type Result struct { | ||||
| 	Ctx *gin.Context | ||||
| } | ||||
|  | ||||
| type BaseResponse struct { | ||||
| 	Code    int    `json:"code"` | ||||
| 	Message string `json:"message"` | ||||
| } | ||||
|  | ||||
| func NewResult(ctx *gin.Context) *Result { | ||||
| 	return &Result{Ctx: ctx} | ||||
| } | ||||
|  | ||||
| // 统一出错信息 | ||||
| func (r *Result) Error(code int, msg string) { | ||||
| 	res := BaseResponse{} | ||||
| 	res.Code = code | ||||
| 	res.Message = msg | ||||
| 	r.Ctx.JSON(http.StatusOK, res) | ||||
| } | ||||
		Reference in New Issue
	
	Block a user