snapshot of https://github.com/cortezaproject/corteza.git (2024.9.x, 2026-09-18; blobs > 131072B omitted)
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
Some checks failed
SonarQube / SonarQube (push) Failing after 5m28s
E2e test on main branch push / server and client test (map[name:admin port:8080]) (push) Failing after 3m33s
Server and lib tests / Library test (js) (push) Failing after 1m36s
Server and lib tests / Library test (vue) (push) Successful in 2m24s
Server and lib tests / Web client test (admin) (push) Successful in 2m52s
Server and lib tests / Web client test (compose) (push) Successful in 3m23s
Server and lib tests / Web client test (discovery) (push) Successful in 2m49s
Server and lib tests / Web client test (one) (push) Successful in 2m52s
Server and lib tests / Web client test (privacy) (push) Successful in 2m44s
Server and lib tests / Web client test (reporter) (push) Successful in 2m56s
Server and lib tests / Web client test (workflow) (push) Successful in 3m0s
Server and lib tests / Server tests (push) Failing after 4m55s
E2e test on main branch push / notify-failure (push) Failing after 9s
Server and lib tests / Send matrix testing notification (push) Successful in 2s
Mark stale issues and pull requests / stale (push) Successful in 40s
This commit is contained in:
13
server/pkg/cast2/boolean.go
Normal file
13
server/pkg/cast2/boolean.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package cast2
|
||||
|
||||
import "github.com/spf13/cast"
|
||||
|
||||
func Bool(in any, out *bool) error {
|
||||
aux, err := cast.ToBoolE(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*out = aux
|
||||
return nil
|
||||
}
|
||||
20
server/pkg/cast2/generic.go
Normal file
20
server/pkg/cast2/generic.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package cast2
|
||||
|
||||
import (
|
||||
"github.com/cortezaproject/corteza/server/pkg/id"
|
||||
"github.com/spf13/cast"
|
||||
)
|
||||
|
||||
func ID(in any, out *id.ID) error {
|
||||
aux, err := cast.ToStringE(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*out, err = id.ByteID([]byte(aux))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
33
server/pkg/cast2/integer.go
Normal file
33
server/pkg/cast2/integer.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package cast2
|
||||
|
||||
import "github.com/spf13/cast"
|
||||
|
||||
func Uint64(in any, out *uint64) error {
|
||||
aux, err := cast.ToUint64E(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*out = aux
|
||||
return nil
|
||||
}
|
||||
|
||||
func Uint(in any, out *uint) error {
|
||||
aux, err := cast.ToUintE(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*out = aux
|
||||
return nil
|
||||
}
|
||||
|
||||
func Int(in any, out *int) error {
|
||||
aux, err := cast.ToIntE(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*out = aux
|
||||
return nil
|
||||
}
|
||||
23
server/pkg/cast2/integer_test.go
Normal file
23
server/pkg/cast2/integer_test.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package cast2
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestUint64(t *testing.T) {
|
||||
var (
|
||||
req = require.New(t)
|
||||
target uint64 = 42
|
||||
)
|
||||
|
||||
req.NoError(Uint64(nil, &target))
|
||||
req.Equal(uint64(0), target)
|
||||
|
||||
req.NoError(Uint64("42", &target))
|
||||
req.Equal(uint64(42), target)
|
||||
|
||||
target = 5
|
||||
req.Error(Uint64("-42", &target))
|
||||
req.Equal(uint64(5), target)
|
||||
}
|
||||
32
server/pkg/cast2/map.go
Normal file
32
server/pkg/cast2/map.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package cast2
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/modern-go/reflect2"
|
||||
)
|
||||
|
||||
// Meta casts a value to a map[string]any
|
||||
func Meta(in any, out *map[string]any) (err error) {
|
||||
if reflect2.IsNil(in) {
|
||||
*out = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
switch aux := in.(type) {
|
||||
case []byte:
|
||||
err = json.Unmarshal(aux, out)
|
||||
case string:
|
||||
err = json.Unmarshal([]byte(aux), out)
|
||||
case map[string]any:
|
||||
*out = aux
|
||||
default:
|
||||
err = fmt.Errorf("unsupported type: %T", in)
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
return
|
||||
}
|
||||
|
||||
return fmt.Errorf("can not cast to Meta: %w", err)
|
||||
}
|
||||
30
server/pkg/cast2/map_test.go
Normal file
30
server/pkg/cast2/map_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package cast2
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMap(t *testing.T) {
|
||||
var (
|
||||
req = require.New(t)
|
||||
)
|
||||
|
||||
{
|
||||
target := make(map[string]any)
|
||||
req.NoError(Meta([]byte(`{"a":"b"}`), &target))
|
||||
req.Equal(map[string]any{"a": "b"}, target)
|
||||
}
|
||||
|
||||
{
|
||||
target := make(map[string]any)
|
||||
req.NoError(Meta(`{"a":"b"}`, &target))
|
||||
req.Equal(map[string]any{"a": "b"}, target)
|
||||
}
|
||||
|
||||
{
|
||||
target := make(map[string]any)
|
||||
req.NoError(Meta(map[string]any{"a": "b"}, &target))
|
||||
req.Equal(map[string]any{"a": "b"}, target)
|
||||
}
|
||||
}
|
||||
12
server/pkg/cast2/slice.go
Normal file
12
server/pkg/cast2/slice.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package cast2
|
||||
|
||||
// Anys converts any kinds of values to a []any slice
|
||||
func Anys[C any](in ...C) (out []any) {
|
||||
out = make([]any, len(in))
|
||||
|
||||
for i := range in {
|
||||
out[i] = in[i]
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
13
server/pkg/cast2/string.go
Normal file
13
server/pkg/cast2/string.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package cast2
|
||||
|
||||
import "github.com/spf13/cast"
|
||||
|
||||
func String(in any, out *string) error {
|
||||
aux, err := cast.ToStringE(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*out = aux
|
||||
return nil
|
||||
}
|
||||
40
server/pkg/cast2/time.go
Normal file
40
server/pkg/cast2/time.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package cast2
|
||||
|
||||
import (
|
||||
"github.com/modern-go/reflect2"
|
||||
"github.com/spf13/cast"
|
||||
"time"
|
||||
)
|
||||
|
||||
func Time(in any, out *time.Time) error {
|
||||
if reflect2.IsNil(in) {
|
||||
if out != nil {
|
||||
*out = time.Time{}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
aux, err := cast.ToTimeE(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*out = aux
|
||||
return nil
|
||||
}
|
||||
|
||||
func TimePtr(in any, out **time.Time) error {
|
||||
if reflect2.IsNil(in) {
|
||||
*out = nil
|
||||
return nil
|
||||
}
|
||||
|
||||
aux, err := cast.ToTimeE(in)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*out = &aux
|
||||
return nil
|
||||
}
|
||||
32
server/pkg/cast2/time_test.go
Normal file
32
server/pkg/cast2/time_test.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package cast2
|
||||
|
||||
import (
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTime(t *testing.T) {
|
||||
var (
|
||||
req = require.New(t)
|
||||
|
||||
target1 time.Time
|
||||
target2 = &time.Time{}
|
||||
|
||||
in = "2006-01-02T15:04:05" // abuse format as value
|
||||
)
|
||||
|
||||
req.NoError(Time(in, &target1))
|
||||
req.Equal(in, target1.Format(in))
|
||||
req.NotZero(target1)
|
||||
|
||||
req.NoError(TimePtr(in, &target2))
|
||||
req.NotNil(target2)
|
||||
req.Equal(in, target2.Format(in))
|
||||
|
||||
req.NoError(Time(nil, &target1))
|
||||
req.Zero(target1)
|
||||
|
||||
req.NoError(TimePtr(nil, &target2))
|
||||
req.Nil(target2)
|
||||
}
|
||||
Reference in New Issue
Block a user