mirror of
https://github.com/Dvorinka/SEEN.git
synced 2026-06-04 12:33:02 +00:00
small fix, don't worry about it
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
package httpx
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
type ErrorResponse struct {
|
||||
Error string `json:"error"`
|
||||
RequestID string `json:"requestId,omitempty"`
|
||||
}
|
||||
|
||||
func JSONError(c *gin.Context, status int, message string) {
|
||||
requestID, _ := c.Get("request_id")
|
||||
|
||||
c.JSON(status, ErrorResponse{
|
||||
Error: message,
|
||||
RequestID: toString(requestID),
|
||||
})
|
||||
}
|
||||
|
||||
func JSON(c *gin.Context, status int, payload any) {
|
||||
c.JSON(status, payload)
|
||||
}
|
||||
|
||||
func toString(value any) string {
|
||||
if value == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
typed, ok := value.(string)
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
return typed
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package logger
|
||||
|
||||
import "go.uber.org/zap"
|
||||
|
||||
func New(env string) *zap.Logger {
|
||||
if env == "production" {
|
||||
log, err := zap.NewProduction()
|
||||
if err == nil {
|
||||
return log
|
||||
}
|
||||
}
|
||||
|
||||
config := zap.NewDevelopmentConfig()
|
||||
config.EncoderConfig.TimeKey = "ts"
|
||||
log, err := config.Build()
|
||||
if err != nil {
|
||||
return zap.Must(zap.NewDevelopment())
|
||||
}
|
||||
|
||||
return log
|
||||
}
|
||||
Reference in New Issue
Block a user