Compare commits

...

4 Commits

Author SHA1 Message Date
7e16e799e4 v0.0.381
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m28s
2024-01-23 17:51:52 +01:00
890e16241d v0.0.380 exerr properly handle inf and nan floats
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m8s
2024-01-22 12:33:41 +01:00
b9d0348735 v0.0.379
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m57s
2024-01-19 17:30:20 +01:00
b9e9575b9b v0.0.378
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 3m18s
2024-01-16 15:04:10 +01:00
6 changed files with 123 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ import (
"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/bson/primitive"
"gogs.mikescher.com/BlackForestBytes/goext/langext"
"math"
"strconv"
"strings"
"time"
@@ -667,6 +668,28 @@ func (v MetaValue) rawValueForJson() any {
}
return v.Value.(EnumWrap).ValueString
}
if v.DataType == MDTFloat32 {
if math.IsNaN(float64(v.Value.(float32))) {
return "float64::NaN"
} else if math.IsInf(float64(v.Value.(float32)), +1) {
return "float64::+inf"
} else if math.IsInf(float64(v.Value.(float32)), -1) {
return "float64::-inf"
} else {
return v.Value
}
}
if v.DataType == MDTFloat64 {
if math.IsNaN(v.Value.(float64)) {
return "float64::NaN"
} else if math.IsInf(v.Value.(float64), +1) {
return "float64::+inf"
} else if math.IsInf(v.Value.(float64), -1) {
return "float64::-inf"
} else {
return v.Value
}
}
return v.Value
}

View File

@@ -163,16 +163,16 @@ func (pctx PreContext) Start() (*AppContext, *gin.Context, *HTTPResponse) {
ictx, cancel := context.WithTimeout(context.Background(), langext.Coalesce(pctx.timeout, pctx.wrapper.requestTimeout))
actx := CreateAppContext(pctx.ginCtx, ictx, cancel)
if pctx.persistantData.sessionObj != nil {
err := pctx.persistantData.sessionObj.Init(pctx.ginCtx, ictx)
err := pctx.persistantData.sessionObj.Init(pctx.ginCtx, actx)
if err != nil {
cancel()
actx.Cancel()
return nil, nil, langext.Ptr(Error(exerr.Wrap(err, "Failed to init session").Build()))
}
}
actx := CreateAppContext(pctx.ginCtx, ictx, cancel)
return actx, pctx.ginCtx, nil
}

View File

@@ -6,6 +6,6 @@ import (
)
type SessionObject interface {
Init(g *gin.Context, ctx context.Context) error
Init(g *gin.Context, ctx *AppContext) error
Finish(ctx context.Context, resp HTTPResponse) error
}

View File

@@ -1,5 +1,5 @@
package goext
const GoextVersion = "0.0.377"
const GoextVersion = "0.0.381"
const GoextVersionTimestamp = "2024-01-14T17:06:42+0100"
const GoextVersionTimestamp = "2024-01-23T17:51:52+0100"

21
langext/must.go Normal file
View File

@@ -0,0 +1,21 @@
package langext
// Must returns a value and panics on error
//
// Usage: Must(methodWithError(...))
func Must[T any](v T, err error) T {
if err != nil {
panic(err)
}
return v
}
// MustBool returns a value and panics on missing
//
// Usage: MustBool(methodWithOkayReturn(...))
func MustBool[T any](v T, ok bool) T {
if !ok {
panic("not ok")
}
return v
}

View File

@@ -0,0 +1,72 @@
package reflectext
import "reflect"
func ConvertStructToMap(v any) any {
return reflectToMap(reflect.ValueOf(v))
}
func reflectToMap(fv reflect.Value) any {
if fv.Kind() == reflect.Ptr {
if fv.IsNil() {
return nil
} else {
return reflectToMap(fv.Elem())
}
}
if fv.Kind() == reflect.Func {
// skip
return nil
}
if fv.Kind() == reflect.Array {
arrlen := fv.Len()
arr := make([]any, arrlen)
for i := 0; i < arrlen; i++ {
arr[i] = reflectToMap(fv.Index(i))
}
return arr
}
if fv.Kind() == reflect.Slice {
arrlen := fv.Len()
arr := make([]any, arrlen)
for i := 0; i < arrlen; i++ {
arr[i] = reflectToMap(fv.Index(i))
}
return arr
}
if fv.Kind() == reflect.Chan {
// skip
return nil
}
if fv.Kind() == reflect.Struct {
res := make(map[string]any)
for i := 0; i < fv.NumField(); i++ {
if fv.Type().Field(i).IsExported() {
res[fv.Type().Field(i).Name] = reflectToMap(fv.Field(i))
}
}
return res
}
return fv.Interface()
}