fieldalignment of all structs to save memory
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
@@ -5,7 +5,6 @@ import (
|
||||
)
|
||||
|
||||
func TestPath(t *testing.T) {
|
||||
|
||||
type Nested2 struct {
|
||||
Name string
|
||||
}
|
||||
|
@@ -9,14 +9,10 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
// ErrInvalidParam specifies invalid url query params
|
||||
ErrInvalidParam = errors.New("invalid url query param provided")
|
||||
)
|
||||
// ErrInvalidParam specifies invalid url query params
|
||||
var ErrInvalidParam = errors.New("invalid url query param provided")
|
||||
|
||||
var (
|
||||
bracketSplitter = regexp.MustCompile(`\[|\]`)
|
||||
)
|
||||
var bracketSplitter = regexp.MustCompile(`\[|\]`)
|
||||
|
||||
// StructFields returns slice of struct fields
|
||||
func StructFields(src interface{}) ([]reflect.StructField, error) {
|
||||
@@ -157,7 +153,7 @@ func StructURLValues(src interface{}, pref string, tags []string) (url.Values, e
|
||||
case reflect.Slice:
|
||||
for i := 0; i < val.Len(); i++ {
|
||||
va := val.Index(i)
|
||||
//if va.Type().Elem().Kind() != reflect.Ptr {
|
||||
// if va.Type().Elem().Kind() != reflect.Ptr {
|
||||
if va.Kind() != reflect.Ptr {
|
||||
data.Set(t.name, fmt.Sprintf("%v", va.Interface()))
|
||||
continue
|
||||
@@ -193,9 +189,7 @@ func StructURLValues(src interface{}, pref string, tags []string) (url.Values, e
|
||||
|
||||
// URLMap returns map of url query params
|
||||
func URLMap(query string) (map[string]interface{}, error) {
|
||||
var (
|
||||
mp interface{} = make(map[string]interface{})
|
||||
)
|
||||
var mp interface{} = make(map[string]interface{})
|
||||
|
||||
params := strings.Split(query, "&")
|
||||
|
||||
|
@@ -7,9 +7,9 @@ import (
|
||||
|
||||
func TestStructURLValues(t *testing.T) {
|
||||
type Str struct {
|
||||
Str *Str `json:"str"`
|
||||
Name string `json:"name"`
|
||||
Args []int `json:"args"`
|
||||
Str *Str `json:"str"`
|
||||
}
|
||||
|
||||
val := &Str{Name: "test_name", Args: []int{1, 2, 3}, Str: &Str{Name: "nested_name"}}
|
||||
@@ -90,8 +90,8 @@ func TestIsZero(t *testing.T) {
|
||||
Nested string
|
||||
}
|
||||
type testStr2 struct {
|
||||
Name string
|
||||
Nested *testStr3
|
||||
Name string
|
||||
}
|
||||
vtest := &testStr2{
|
||||
Name: "test_name",
|
||||
@@ -106,5 +106,5 @@ func TestIsZero(t *testing.T) {
|
||||
t.Fatalf("non zero ret on zero struct: %#+v", vtest)
|
||||
}
|
||||
|
||||
//t.Logf("XX %#+v\n", ok)
|
||||
// t.Logf("XX %#+v\n", ok)
|
||||
}
|
||||
|
Reference in New Issue
Block a user