Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/han-ya-jun/struct2map


https://github.com/han-ya-jun/struct2map

Last synced: 19 days ago
JSON representation

Awesome Lists containing this project

README

        

# struct2map
```go
func TestStruct2mapCase1(t *testing.T) {
type User struct {
UserName string `struct2map:"user_name,omitempty" json:"user_name"`
Age int `struct2map:"-" json:"age"`
}
user:=User{
UserName: "",
Age: 23,
}
struct2map, err := Struct2map(&user)
if err!=nil{
t.Fatal(err)
}
t.Logf("%v",struct2map)
}

func TestStruct2mapCase2(t *testing.T) {
type User struct {
UserName string `struct2map:"user_name,omitempty" json:"user_name"`
Age *int `struct2map:"age,omitempty" json:"age"`
}
user:=User{
UserName: "qwe",
Age: nil,
}
struct2map, err := Struct2map(&user)
if err!=nil{
t.Fatal(err)
}
t.Logf("%v",struct2map)
}

func BenchmarkStruct2map(b *testing.B) {
type User struct {
UserName string `struct2map:"user_name,omitempty" json:"user_name"`
Age int `struct2map:"-" json:"age"`
}
user:=User{
UserName: "",
Age: 23,
}
struct2map, err := Struct2map(&user)
if err!=nil{
b.Fatal(err)
}
b.Logf("%v",struct2map)
}

```