Compare commits
No commits in common. "main" and "v0.0.15" have entirely different histories.
|
@ -41,6 +41,10 @@ func New(srvKey string, cfg any) {
|
||||||
log.Fatalln("ERROR: Service Not Nil", cfp)
|
log.Fatalln("ERROR: Service Not Nil", cfp)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !strings.Contains(string(yamlFile), "Port:") {
|
||||||
|
log.Fatalln("ERROR: Port Not Nil", cfp)
|
||||||
|
}
|
||||||
|
|
||||||
// 解析YAML
|
// 解析YAML
|
||||||
err = yaml.Unmarshal(yamlFile, cfg)
|
err = yaml.Unmarshal(yamlFile, cfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,7 +55,7 @@ func New(srvKey string, cfg any) {
|
||||||
func NotNil(values ...string) {
|
func NotNil(values ...string) {
|
||||||
for _, value := range values {
|
for _, value := range values {
|
||||||
if strings.TrimSpace(value) == "" {
|
if strings.TrimSpace(value) == "" {
|
||||||
log.Fatalln("ERROR:Must config key not nil")
|
log.Fatalln("ERROR:Must config not nil")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,10 @@ var (
|
||||||
ErrHeaderRequestId = NewError(101, "Header Request-Id Not Found")
|
ErrHeaderRequestId = NewError(101, "Header Request-Id Not Found")
|
||||||
ErrHeaderAuthorization = NewError(102, "Header Authorization Not Found")
|
ErrHeaderAuthorization = NewError(102, "Header Authorization Not Found")
|
||||||
ErrHeaderSecretKey = NewError(103, "Header Secret-Key Not Found")
|
ErrHeaderSecretKey = NewError(103, "Header Secret-Key Not Found")
|
||||||
ErrHeaderMustParams = NewError(104, "Header Must Params")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// standard error code ,start:110
|
// standard error code ,start:110
|
||||||
var (
|
var (
|
||||||
ErrEmpty = NewError(110, "Data Is Empty")
|
|
||||||
ErrRequestParse = NewError(111, "Request Parse Fail")
|
ErrRequestParse = NewError(111, "Request Parse Fail")
|
||||||
ErrRequestMust = NewError(112, "Request Params Required")
|
ErrRequestMust = NewError(112, "Request Params Required")
|
||||||
ErrPermission = NewError(113, "Permission Denied")
|
ErrPermission = NewError(113, "Permission Denied")
|
||||||
|
|
|
@ -16,7 +16,6 @@ type Reply struct {
|
||||||
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||||
reply.Code = 200
|
reply.Code = 200
|
||||||
reply.Data = data
|
reply.Data = data
|
||||||
reply.Msg = ""
|
|
||||||
if data == nil {
|
if data == nil {
|
||||||
reply.Data = ""
|
reply.Data = ""
|
||||||
}
|
}
|
||||||
|
@ -24,12 +23,12 @@ func (reply *Reply) Success(ctx *gin.Context, data any) {
|
||||||
}
|
}
|
||||||
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
func (reply *Reply) Error(ctx *gin.Context, err error) {
|
||||||
reply.Code = 500
|
reply.Code = 500
|
||||||
reply.Data = ""
|
|
||||||
// Status code defaults to 500
|
// Status code defaults to 500
|
||||||
e, ok := status.FromError(err)
|
e, ok := status.FromError(err)
|
||||||
if ok {
|
if ok {
|
||||||
reply.Code = int(e.Code())
|
reply.Code = int(e.Code())
|
||||||
}
|
}
|
||||||
|
|
||||||
reply.Msg = e.Message()
|
reply.Msg = e.Message()
|
||||||
|
|
||||||
// Send error
|
// Send error
|
||||||
|
|
|
@ -3,36 +3,28 @@ package print
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var logger *log.Logger
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
logger = log.New(os.Stdout, "", 0) // 创建一个新的 Logger 实例,不带任何标志
|
|
||||||
logger.SetFlags(log.Ldate | log.Ltime)
|
|
||||||
}
|
|
||||||
|
|
||||||
// record INFO message. Color White
|
// record INFO message. Color White
|
||||||
func Info(format string, a ...interface{}) {
|
func Info(format string, a ...interface{}) {
|
||||||
message := fmt.Sprintf("\033[37m[Info] "+format+"\033[0m\n", a...)
|
message := fmt.Sprintf("\033[37m[Info] "+format+"\033[0m\n", a...)
|
||||||
logger.Print(message)
|
log.Print(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// record Warn message. Color Orange
|
// record Warn message. Color Orange
|
||||||
func Warn(format string, a ...interface{}) {
|
func Warn(format string, a ...interface{}) {
|
||||||
message := fmt.Sprintf("\033[33m[Warn] "+format+"\033[0m\n", a...)
|
message := fmt.Sprintf("\033[33m[Warn] "+format+"\033[0m\n", a...)
|
||||||
logger.Print(message)
|
log.Print(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// record Success message. Color Green
|
// record Success message. Color Green
|
||||||
func Success(format string, a ...interface{}) {
|
func Success(format string, a ...interface{}) {
|
||||||
message := fmt.Sprintf("\033[32m[Success] "+format+"\033[0m\n", a...)
|
message := fmt.Sprintf("\033[32m[Success] "+format+"\033[0m\n", a...)
|
||||||
logger.Print(message)
|
log.Print(message)
|
||||||
}
|
}
|
||||||
|
|
||||||
// record ERROR message. Color Red
|
// record ERROR message. Color Red
|
||||||
func Error(format string, a ...interface{}) {
|
func Error(format string, a ...interface{}) {
|
||||||
message := fmt.Sprintf("\033[31m[Error] "+format+"\033[0m\n", a...)
|
message := fmt.Sprintf("\033[31m[Error] "+format+"\033[0m\n", a...)
|
||||||
logger.Print(message)
|
log.Print(message)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue