feat: statistics: finish dev

This commit is contained in:
fallen-angle
2022-01-23 18:28:01 +08:00
parent 582807ae10
commit d844711191
29 changed files with 1670 additions and 51 deletions

17
utils/list.go Normal file
View File

@@ -0,0 +1,17 @@
package utils
type ObjectType []interface{}
func ForEach[T any](arr *[]T, fun func(item *T)) {
for i := range *arr {
fun(&((*arr)[i]))
}
}
func Map[T any, V any](arr []T, fun func(item T) V) []V {
res := make([]V, 0, len(arr))
for _, item := range arr {
res = append(res, fun(item))
}
return res
}

View File

@@ -40,13 +40,19 @@ func UtilLogWarn(utilName string, args ...interface{}) {
}
func logInfo(msg string, args ...interface{}) {
global.Logger.Infow(msg, args...)
if global.ServerSettings.Env != global.ENV_NOLOG {
global.Logger.Infow(msg, args...)
}
}
func logError(msg string, args ...interface{}) {
global.Logger.Errorw(msg, args...)
}
if global.ServerSettings.Env != global.ENV_NOLOG {
global.Logger.Errorw(msg, args...)
func logWarn(msg string, args ...interface{}) {
global.Logger.Warnw(msg, args...)
}
}
func logWarn(msg string, args ...interface{}) {
if global.ServerSettings.Env != global.ENV_NOLOG {
global.Logger.Warnw(msg, args...)
}
}

20
utils/response.go Normal file
View File

@@ -0,0 +1,20 @@
package utils
import (
"nCovTrack-Backend/models"
"net/http"
"github.com/gin-gonic/gin"
)
func Success(c *gin.Context, code int, msg interface{}, data interface{}) {
c.JSON(http.StatusOK, models.GinResponse{Code: code, Msg: msg, Data: data})
}
func Error(c *gin.Context, status int, code int, msg interface{}, data interface{}) {
c.JSON(status, models.GinResponse{Code: code, Msg: msg, Data: data})
}
func Succ(c *gin.Context, data interface{}) {
Success(c, http.StatusOK, "success", data)
}

1
utils/string.go Normal file
View File

@@ -0,0 +1 @@
package utils

7
utils/struct.go Normal file
View File

@@ -0,0 +1,7 @@
package utils
func Copy[T any](old *T) T {
T1 := *old
T2 := *&T1
return T2
}