From 47f123b86f060c9cc2917ab37320884a7f39ab78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Thu, 27 Oct 2022 16:07:42 +0200 Subject: [PATCH] remove ginext/mongoext (no-dep lib) --- {lang/cryptext => cryptext}/hash.go | 0 {lang/cryptext => cryptext}/hash_test.go | 0 .../dataext => dataext}/bufferedReadCloser.go | 0 {lang/dataext => dataext}/lruMap.go | 0 {lang/dataext => dataext}/lruMap_test.go | 0 {lang/dataext => dataext}/syncSet.go | 0 error/bfberror/TODO | 0 error/go.mod | 3 - gin/ginext/bindings.go | 69 ------------------- gin/ginext/gin.go | 42 ----------- gin/go.mod | 3 - lang/go.mod => go.mod | 0 {lang/langext => langext}/array.go | 0 {lang/langext => langext}/bytes.go | 0 {lang/langext => langext}/coalesce.go | 0 {lang/langext => langext}/compare.go | 0 {lang/langext => langext}/pointer.go | 0 {lang/langext => langext}/string.go | 0 {lang/mathext => mathext}/clamp.go | 0 {lang/mathext => mathext}/float.go | 0 {lang/mathext => mathext}/math.go | 0 {lang/mathext => mathext}/statistics.go | 0 mongo/go.mod | 6 -- mongo/mongoext/TODO | 0 {lang/timeext => timeext}/duration.go | 0 {lang/timeext => timeext}/range.go | 0 {lang/timeext => timeext}/time.go | 6 ++ {lang/timeext => timeext}/translation.go | 0 {lang/timeext => timeext}/weekcount.go | 0 {lang/totpext => totpext}/totp.go | 0 {lang/zipext => zipext}/zip.go | 0 31 files changed, 6 insertions(+), 123 deletions(-) rename {lang/cryptext => cryptext}/hash.go (100%) rename {lang/cryptext => cryptext}/hash_test.go (100%) rename {lang/dataext => dataext}/bufferedReadCloser.go (100%) rename {lang/dataext => dataext}/lruMap.go (100%) rename {lang/dataext => dataext}/lruMap_test.go (100%) rename {lang/dataext => dataext}/syncSet.go (100%) delete mode 100644 error/bfberror/TODO delete mode 100644 error/go.mod delete mode 100644 gin/ginext/bindings.go delete mode 100644 gin/ginext/gin.go delete mode 100644 gin/go.mod rename lang/go.mod => go.mod (100%) rename {lang/langext => langext}/array.go (100%) rename {lang/langext => langext}/bytes.go (100%) rename {lang/langext => langext}/coalesce.go (100%) rename {lang/langext => langext}/compare.go (100%) rename {lang/langext => langext}/pointer.go (100%) rename {lang/langext => langext}/string.go (100%) rename {lang/mathext => mathext}/clamp.go (100%) rename {lang/mathext => mathext}/float.go (100%) rename {lang/mathext => mathext}/math.go (100%) rename {lang/mathext => mathext}/statistics.go (100%) delete mode 100644 mongo/go.mod delete mode 100644 mongo/mongoext/TODO rename {lang/timeext => timeext}/duration.go (100%) rename {lang/timeext => timeext}/range.go (100%) rename {lang/timeext => timeext}/time.go (96%) rename {lang/timeext => timeext}/translation.go (100%) rename {lang/timeext => timeext}/weekcount.go (100%) rename {lang/totpext => totpext}/totp.go (100%) rename {lang/zipext => zipext}/zip.go (100%) diff --git a/lang/cryptext/hash.go b/cryptext/hash.go similarity index 100% rename from lang/cryptext/hash.go rename to cryptext/hash.go diff --git a/lang/cryptext/hash_test.go b/cryptext/hash_test.go similarity index 100% rename from lang/cryptext/hash_test.go rename to cryptext/hash_test.go diff --git a/lang/dataext/bufferedReadCloser.go b/dataext/bufferedReadCloser.go similarity index 100% rename from lang/dataext/bufferedReadCloser.go rename to dataext/bufferedReadCloser.go diff --git a/lang/dataext/lruMap.go b/dataext/lruMap.go similarity index 100% rename from lang/dataext/lruMap.go rename to dataext/lruMap.go diff --git a/lang/dataext/lruMap_test.go b/dataext/lruMap_test.go similarity index 100% rename from lang/dataext/lruMap_test.go rename to dataext/lruMap_test.go diff --git a/lang/dataext/syncSet.go b/dataext/syncSet.go similarity index 100% rename from lang/dataext/syncSet.go rename to dataext/syncSet.go diff --git a/error/bfberror/TODO b/error/bfberror/TODO deleted file mode 100644 index e69de29..0000000 diff --git a/error/go.mod b/error/go.mod deleted file mode 100644 index 7b874f7..0000000 --- a/error/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module blackforestbytes.com/goext/error - -go 1.19 diff --git a/gin/ginext/bindings.go b/gin/ginext/bindings.go deleted file mode 100644 index 80c03ee..0000000 --- a/gin/ginext/bindings.go +++ /dev/null @@ -1,69 +0,0 @@ -package ginext - -import ( - "bringman.de/common/shared/bmerror" - "github.com/gin-gonic/gin" - "github.com/go-playground/validator/v10" - "net/http" -) - -func ShouldBind(g *gin.Context, uri interface{}, query interface{}, body interface{}) error { - if uri != nil { - if err := g.ShouldBindUri(uri); err != nil { - if vErrs, ok := err.(validator.ValidationErrors); ok { - return bmerror.Wrap(vErrs, "Could not validate request parameter (uri)"). - Errs("inner", convertValidationErrors(vErrs)). - WithType(bmerror.ErrQueryValidation). - WithStatuscode(http.StatusBadRequest). - Build() - } else { - return bmerror.Wrap(err, "Could not parse request parameter (uri)"). - WithType(bmerror.ErrQueryParse). - WithStatuscode(http.StatusBadRequest). - Build() - } - } - } - if query != nil { - if err := g.ShouldBindQuery(query); err != nil { - if vErrs, ok := err.(validator.ValidationErrors); ok { - return bmerror.Wrap(vErrs, "Could not validate request parameter (query)"). - Errs("inner", convertValidationErrors(vErrs)). - WithType(bmerror.ErrQueryValidation). - WithStatuscode(http.StatusBadRequest). - Build() - } else { - return bmerror.Wrap(err, "Could not parse request parameter (query)"). - WithType(bmerror.ErrQueryParse). - WithStatuscode(http.StatusBadRequest). - Build() - } - } - } - if body != nil { - if err := g.ShouldBindJSON(body); err != nil { - if vErrs, ok := err.(validator.ValidationErrors); ok { - return bmerror.Wrap(vErrs, "Could not validate request parameter (body:json)"). - Errs("inner", convertValidationErrors(vErrs)). - WithType(bmerror.ErrQueryValidation). - WithStatuscode(http.StatusBadRequest). - Build() - } else { - return bmerror.Wrap(err, "Could not parse request parameter (body:json)"). - WithType(bmerror.ErrQueryParse). - WithStatuscode(http.StatusBadRequest). - Build() - } - } - } - - return nil -} - -func convertValidationErrors(e validator.ValidationErrors) []error { - r := make([]error, 0, len(e)) - for _, v := range e { - r = append(r, v) - } - return r -} diff --git a/gin/ginext/gin.go b/gin/ginext/gin.go deleted file mode 100644 index 5ad1e37..0000000 --- a/gin/ginext/gin.go +++ /dev/null @@ -1,42 +0,0 @@ -package ginext - -import ( - "bringman.de/common/shared/bmerror" - "context" - "github.com/gin-gonic/gin" - "net/http" -) - -func NewEngine() *gin.Engine { - engine := gin.New() - - engine.RedirectFixedPath = false - engine.RedirectTrailingSlash = false - - engine.Use(gin.CustomRecovery(func(c *gin.Context, err interface{}) { - ctx := context.Background() - - bmerror. - New(bmerror.ErrGinPanic, "gin request caused panic"). - Interface("panic-object", err). - Stack(). - GinReq(ctx, c, c.Request). - WithStatuscode(http.StatusInternalServerError). - Output(ctx, c) - })) - - return engine -} - -func NoRouteHandler() func(c *gin.Context) { - return func(g *gin.Context) { - bmerror.New(bmerror.ErrRouteNotFound, "Route not found"). - Str("FullPath", g.FullPath()). - Str("Method", g.Request.Method). - Str("URL", g.Request.URL.String()). - Str("RequestURI", g.Request.RequestURI). - Str("Proto", g.Request.Proto). - Any("Header", g.Request.Header). - Output(context.Background(), g) - } -} diff --git a/gin/go.mod b/gin/go.mod deleted file mode 100644 index 39cfc8b..0000000 --- a/gin/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module blackforestbytes.com/goext/gin - -go 1.19 diff --git a/lang/go.mod b/go.mod similarity index 100% rename from lang/go.mod rename to go.mod diff --git a/lang/langext/array.go b/langext/array.go similarity index 100% rename from lang/langext/array.go rename to langext/array.go diff --git a/lang/langext/bytes.go b/langext/bytes.go similarity index 100% rename from lang/langext/bytes.go rename to langext/bytes.go diff --git a/lang/langext/coalesce.go b/langext/coalesce.go similarity index 100% rename from lang/langext/coalesce.go rename to langext/coalesce.go diff --git a/lang/langext/compare.go b/langext/compare.go similarity index 100% rename from lang/langext/compare.go rename to langext/compare.go diff --git a/lang/langext/pointer.go b/langext/pointer.go similarity index 100% rename from lang/langext/pointer.go rename to langext/pointer.go diff --git a/lang/langext/string.go b/langext/string.go similarity index 100% rename from lang/langext/string.go rename to langext/string.go diff --git a/lang/mathext/clamp.go b/mathext/clamp.go similarity index 100% rename from lang/mathext/clamp.go rename to mathext/clamp.go diff --git a/lang/mathext/float.go b/mathext/float.go similarity index 100% rename from lang/mathext/float.go rename to mathext/float.go diff --git a/lang/mathext/math.go b/mathext/math.go similarity index 100% rename from lang/mathext/math.go rename to mathext/math.go diff --git a/lang/mathext/statistics.go b/mathext/statistics.go similarity index 100% rename from lang/mathext/statistics.go rename to mathext/statistics.go diff --git a/mongo/go.mod b/mongo/go.mod deleted file mode 100644 index 5112f77..0000000 --- a/mongo/go.mod +++ /dev/null @@ -1,6 +0,0 @@ -module blackforestbytes.com/goext/mongo - -require ( - go.mongodb.org/mongo-driver v1.5.3 -) -go 1.19 diff --git a/mongo/mongoext/TODO b/mongo/mongoext/TODO deleted file mode 100644 index e69de29..0000000 diff --git a/lang/timeext/duration.go b/timeext/duration.go similarity index 100% rename from lang/timeext/duration.go rename to timeext/duration.go diff --git a/lang/timeext/range.go b/timeext/range.go similarity index 100% rename from lang/timeext/range.go rename to timeext/range.go diff --git a/lang/timeext/time.go b/timeext/time.go similarity index 96% rename from lang/timeext/time.go rename to timeext/time.go index 61bd94f..93ef670 100644 --- a/lang/timeext/time.go +++ b/timeext/time.go @@ -2,6 +2,7 @@ package timeext import ( "fmt" + "math" "time" ) @@ -125,3 +126,8 @@ func Max(a time.Time, b time.Time) time.Time { return b } } + +func UnixFloatSeconds(v float64) time.Time { + sec, dec := math.Modf(v) + return time.Unix(int64(sec), int64(dec*(1e9))) +} diff --git a/lang/timeext/translation.go b/timeext/translation.go similarity index 100% rename from lang/timeext/translation.go rename to timeext/translation.go diff --git a/lang/timeext/weekcount.go b/timeext/weekcount.go similarity index 100% rename from lang/timeext/weekcount.go rename to timeext/weekcount.go diff --git a/lang/totpext/totp.go b/totpext/totp.go similarity index 100% rename from lang/totpext/totp.go rename to totpext/totp.go diff --git a/lang/zipext/zip.go b/zipext/zip.go similarity index 100% rename from lang/zipext/zip.go rename to zipext/zip.go