feat: statistics: finish dev
This commit is contained in:
17
utils/list.go
Normal file
17
utils/list.go
Normal 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
|
||||
}
|
||||
16
utils/log.go
16
utils/log.go
@@ -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
20
utils/response.go
Normal 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
1
utils/string.go
Normal file
@@ -0,0 +1 @@
|
||||
package utils
|
||||
7
utils/struct.go
Normal file
7
utils/struct.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package utils
|
||||
|
||||
func Copy[T any](old *T) T {
|
||||
T1 := *old
|
||||
T2 := *&T1
|
||||
return T2
|
||||
}
|
||||
Reference in New Issue
Block a user