Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/han-ya-jun/struct2map
https://github.com/han-ya-jun/struct2map
Last synced: 19 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/han-ya-jun/struct2map
- Owner: Han-Ya-Jun
- License: apache-2.0
- Created: 2020-07-11T17:57:57.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-07-30T09:09:08.000Z (over 4 years ago)
- Last Synced: 2024-04-16T04:47:18.059Z (9 months ago)
- Language: Go
- Size: 7.81 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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)
}```