mirror of
https://github.com/minoplhy/chibisafe-netproxy.git
synced 2024-11-22 03:27:08 +00:00
add: zerologger as log library
This commit is contained in:
parent
2c2f6a24d2
commit
f44280abb9
8
go.mod
8
go.mod
@ -1,3 +1,11 @@
|
|||||||
module github.com/minoplhy/chibisafe_netstorage_middleman
|
module github.com/minoplhy/chibisafe_netstorage_middleman
|
||||||
|
|
||||||
go 1.22.2
|
go 1.22.2
|
||||||
|
|
||||||
|
require github.com/rs/zerolog v1.32.0
|
||||||
|
|
||||||
|
require (
|
||||||
|
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||||
|
github.com/mattn/go-isatty v0.0.19 // indirect
|
||||||
|
golang.org/x/sys v0.12.0 // indirect
|
||||||
|
)
|
||||||
|
15
go.sum
15
go.sum
@ -0,0 +1,15 @@
|
|||||||
|
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||||
|
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||||
|
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||||
|
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||||
|
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||||
|
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
|
||||||
|
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||||
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
|
github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
|
||||||
|
github.com/rs/zerolog v1.32.0 h1:keLypqrlIjaFsbmJOBdB/qvyF8KEtCWHwobLp5l/mQ0=
|
||||||
|
github.com/rs/zerolog v1.32.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
|
||||||
|
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o=
|
||||||
|
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
@ -3,11 +3,12 @@ package handler
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetTempFilename(Filename string) string {
|
func GetTempFilename(Filename string) string {
|
||||||
@ -18,13 +19,13 @@ func GetTempFilename(Filename string) string {
|
|||||||
func SaveFile(filename string, file multipart.File) error {
|
func SaveFile(filename string, file multipart.File) error {
|
||||||
err := os.MkdirAll("./uploads", os.ModePerm)
|
err := os.MkdirAll("./uploads", os.ModePerm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic().Msg(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
dst, err := os.Create(filename)
|
dst, err := os.Create(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic().Msg(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ func SaveFile(filename string, file multipart.File) error {
|
|||||||
// at the specified destination
|
// at the specified destination
|
||||||
_, err = io.Copy(dst, file)
|
_, err = io.Copy(dst, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic().Msg(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -43,7 +44,7 @@ func SaveFile(filename string, file multipart.File) error {
|
|||||||
func DeleteFile(filePath string) error {
|
func DeleteFile(filePath string) error {
|
||||||
err := os.Remove(filePath)
|
err := os.Remove(filePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic().Msg(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -53,7 +54,7 @@ func DiscardFile(file multipart.File) error {
|
|||||||
// Clear the data from memory
|
// Clear the data from memory
|
||||||
_, err := io.Copy(io.Discard, file)
|
_, err := io.Copy(io.Discard, file)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Panic(err)
|
log.Panic().Msg(err.Error())
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
@ -2,8 +2,9 @@ package handler
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/rs/zerolog/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
func ErrorResponseBuild(StatusCode int64, Message string) string {
|
func ErrorResponseBuild(StatusCode int64, Message string) string {
|
||||||
@ -15,8 +16,12 @@ func ErrorResponseBuild(StatusCode int64, Message string) string {
|
|||||||
return string(Response)
|
return string(Response)
|
||||||
}
|
}
|
||||||
|
|
||||||
func LogBuilder(Level string, headers []string, message string) {
|
func InfoLogBuilder(headers []string, message string) {
|
||||||
logString := "[" + Level + "]" + " "
|
logString := "[" + strings.Join(headers, "] [") + "]" + " : " + message
|
||||||
logString += "[" + strings.Join(headers, "] [") + "]" + " : " + message
|
log.Info().Msgf(logString)
|
||||||
log.Println(logString)
|
}
|
||||||
|
|
||||||
|
func ErrorLogBuilder(headers []string, message string) {
|
||||||
|
logString := "[" + strings.Join(headers, "] [") + "]" + " : " + message
|
||||||
|
log.Error().Msgf(logString)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user