Browse Source

基础框架搭建完毕

wanghuidong 4 years ago
parent
commit
7626bdce81
4 changed files with 108 additions and 0 deletions
  1. 18 0
      manage/user/user.go
  2. 75 0
      model/response/response.go
  3. 2 0
      router/route.go
  4. 13 0
      test/manage/user_test.go

+ 18 - 0
manage/user/user.go

@@ -1 +1,19 @@
 package user
+
+import (
+	"github.com/gin-gonic/gin"
+	"go.uber.org/zap"
+	"sfbase/global"
+)
+
+func DevUserManageRegister(router *gin.Engine) {
+	userGroup := router.Group("/manage/user/")
+	userGroup.Use()
+	{
+		userGroup.POST("/create", userCreate)
+	}
+}
+
+func userCreate(context *gin.Context) {
+	global.Logger.Info("创建user", zap.Any("app_id:", "yhet6332h"), zap.Any("secret_key", "ffh2273hjd"))
+}

+ 75 - 0
model/response/response.go

@@ -0,0 +1,75 @@
+package response
+
+import (
+	"github.com/gin-gonic/gin"
+	"net/http"
+)
+
+const (
+	ERROR   int = -1
+	SUCCESS int = 0
+	//服务级错误码
+	EmptyResult                  int = 201 //查询无结果
+	ParamError                   int = 202 //参数错误
+	ParamLenInValid              int = 203 //参数长度小于4
+	Waiting                      int = 204 //等待处理中
+	MoreThanQueryDataNumberLimit int = 205 //请求数据的条数超过上限
+	QueryError                   int = 299 //系统查询异常,请联系客服
+
+	//系统级错误码
+	InValidKey    = 101 //当前KEY无效
+	RemainingLack = 102 //当前KEY余额|余量不足
+	DeleteKey     = 103 //当前Key被暂停使用,请联系管理员
+	TokenInvalid  = 104 //身份验证错误或者已过期
+	//105非法请求过多,请联系管理员
+	IpInvalid                       = 106 //被禁止的IP
+	MoreThanEveryDayQueryTimesLimit = 107 //请求超过每日系统限制
+	//108当前相同查询连续出错,请等2小时后重试
+	InterfaceRightInvalid           = 109 //接口权限未开通
+	InterfaceExpired                = 110 //您的账号剩余使用量已过期
+	InterfaceDeleted                = 111 //接口已停用,请联系管理员
+	MoreThanEveryDayDataNumberLimit = 112 //请求超过每日调用总量限制
+	OtherError                      = 199 //系统未知错误,请联系技术客服
+)
+
+type Response struct {
+	Code int         `json:"code"`
+	Data interface{} `json:"data"`
+	Msg  string      `json:"msg"`
+}
+
+func Result(code int, data interface{}, msg string, c *gin.Context) {
+	c.JSON(http.StatusOK, Response{
+		code,
+		data,
+		msg,
+	})
+}
+
+func Ok(c *gin.Context) {
+	Result(SUCCESS, map[string]interface{}{}, "操作成功", c)
+}
+
+func OkWithMessage(message string, c *gin.Context) {
+	Result(SUCCESS, map[string]interface{}{}, message, c)
+}
+
+func OkWithData(data interface{}, c *gin.Context) {
+	Result(SUCCESS, data, "操作成功", c)
+}
+
+func OkWithDetailed(data interface{}, message string, c *gin.Context) {
+	Result(SUCCESS, data, message, c)
+}
+
+func Fail(c *gin.Context) {
+	Result(ERROR, map[string]interface{}{}, "操作失败", c)
+}
+
+func FailWithMessage(message string, c *gin.Context) {
+	Result(ERROR, map[string]interface{}{}, message, c)
+}
+
+func FailWithDetailed(code int, data interface{}, message string, c *gin.Context) {
+	Result(code, data, message, c)
+}

+ 2 - 0
router/route.go

@@ -3,6 +3,7 @@ package router
 import (
 	"github.com/gin-gonic/gin"
 	v1 "sfis/api/v1"
+	"sfis/manage/user"
 )
 
 func InitRouter(middleware ...gin.HandlerFunc) *gin.Engine {
@@ -14,5 +15,6 @@ func InitRouter(middleware ...gin.HandlerFunc) *gin.Engine {
 		})
 	})
 	v1.ProjectApiRegister(router)
+	user.DevUserManageRegister(router)
 	return router
 }

+ 13 - 0
test/manage/user_test.go

@@ -0,0 +1,13 @@
+package manage
+
+import (
+	"log"
+	"testing"
+)
+
+func init() {
+	//todo init connection db operation
+}
+func Test_CreateUser(t *testing.T) {
+	log.Println("devUserCreate testing......")
+}