https://github.com/asppj/goload
https://github.com/asppj/goload
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/asppj/goload
- Owner: asppj
- Created: 2022-07-28T12:10:35.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-08-09T03:03:19.000Z (almost 3 years ago)
- Last Synced: 2024-06-21T03:17:43.319Z (about 1 year ago)
- Language: Go
- Size: 49.8 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# goload
parse default value from struct tag.
```
type Redis struct {
Host string `json:"host" default:"127.0.0.1"`
Port int `json:"port" default:"5678"`
DB int8 `json:"DB" default:"5"`
Enable bool `json:"enable" default:"true"`
}
``````
func TestRedis(t *testing.T) {
c := conf.Redis{DB: 4}
if err := LoadStruct(&c, "default"); err != nil {
t.Fatal(err)
}
t.Logf("%+v", c)
}```
print result is
```
{
Host:127.0.0.1
Port:5678
DB:4
Enable:true
}
```