https://github.com/acim/bee
Microservice abstraction
https://github.com/acim/bee
Last synced: 11 months ago
JSON representation
Microservice abstraction
- Host: GitHub
- URL: https://github.com/acim/bee
- Owner: acim
- License: apache-2.0
- Created: 2025-07-17T14:46:55.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2025-07-17T16:26:01.000Z (11 months ago)
- Last Synced: 2025-07-17T19:13:03.042Z (11 months ago)
- Language: Go
- Size: 18.6 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
# bee
Microservices oriented [12-factor](https://12factor.net) Go library for parsing environment variables and command line flags to arbitrary config struct using struct tags to define default values and to override flag names and environment variables' names.
[](https://github.com/acim/bee/actions/workflows/pipeline.yml)

[](https://pkg.go.dev/go.acim.net/bee)
[](https://goreportcard.com/report/go.acim.net/bee)
This package in intended to be used to parse command line arguments and environment variables into an arbitrary config struct.
This struct may contain multiple nested structs, they all will be processed recursively. Names of the flags and environment
variables are automatically generated. Flags will be kebab case of the field name eventually preceded by parent fields
in case of nested structs. Names of environment variables will be similar, but additionally prefixed with command name
and then snake and upper cased. Description of each flag will also be automatically generated in a human friendly way
as much as possible. Additionally, you may override these auto-generated names using the struct tags and you also may
define default value.
- **flag** - override generated flag name
- **env** - override generated environment variable name
- **help** - override generated flag description
- **def** - override default (zero) value
## Important: all struct fields should be exported.
## Custom flag types
Besides the types supported by flag package, this package provides additional types:
- **bee.StringSlice** - doesn't support multiple flags but instead supports comma separated strings, i.e. "foo,bar"
- **bee.IntSlice** - doesn't support multiple flags but instead supports comma separated integers, i.e. "5,-8,0"
- **bee.URL**
- **bee.Time** - RFC3339 time
## Order of precedence:
- command line options
- environment variables
- default values
## [Examples](example_test.go)
Run `make test-verbose` to see examples output.
## Subcommands
These are handled just like by standard library's flag package.
```go
package main
import (
"log"
"os"
"go.acim.net/bee"
)
func main() {
subCmd := os.Args[1]
switch subCmd {
case "create":
config := &struct{}{}
createCmd := bee.NewCommandLine("create")
if err := createCmd.Parse(config, os.Args[2:]); err != nil {
log.Println(err)
}
// Implementation
case "delete":
config := &struct{}{}
deleteCmd := ms.New("create")
if err := deleteCmd.Parse(config, os.Args[2:]); err != nil {
log.Println(err)
}
// Implementation
}
}
```
## TODO
- support req struct tag to mark required values
## License
Licensed under either of
- Apache License, Version 2.0
([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license
([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
at your option.
## Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.