https://github.com/mehrdadrad/stags
Go library to get and convert struct tags values
https://github.com/mehrdadrad/stags
golang library package struct structure tag
Last synced: 10 months ago
JSON representation
Go library to get and convert struct tags values
- Host: GitHub
- URL: https://github.com/mehrdadrad/stags
- Owner: mehrdadrad
- License: mit
- Created: 2019-11-15T17:04:49.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-17T04:49:03.000Z (about 6 years ago)
- Last Synced: 2025-02-26T05:41:39.988Z (over 1 year ago)
- Topics: golang, library, package, struct, structure, tag
- Language: Go
- Homepage:
- Size: 13.7 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# stags
[](https://travis-ci.org/mehrdadrad/stags)
[](https://goreportcard.com/report/github.com/mehrdadrad/stags)
[](https://gocover.io/github.com/mehrdadrad/stags)
[](https://godoc.org/github.com/mehrdadrad/stags)
Go library to get and convert struct tags values
## Features
- supports nested structure
- convert the tag's value to given data type
## Installation
Standard `go get`:
```bash
$ go get github.com/mehrdadrad/stags
```
## Usage & Example
For usage and examples see the [Godoc](http://godoc.org/github.com/mehrdadrad/stags).
```go
type Configuration struct {
Debug bool `json:"debug" env:"CFG_DEBUG" default:"true"`
Proxy struct {
Address string `json:"address" env:"CFG_ADDR" default:"localhost"`
Port string `json:"port" env:"CFG_PORT" default:"8080"`
}
}
```
```go
func main() {
cfg := Configuration{}
s := stags.New(cfg)
debug := s.GetBool("default", "Debug") // returns true, type: bool
pEnvKey := s.Get("env", "Proxy", "Address") // returns CFG_ADDR, type: string
value, ok := s.LookupInt64("timeout", "proxy", "timeout") // ok: false
}
```
## License
This project is licensed under MIT license. Please read the LICENSE file.