Skip to content

Commit

Permalink
docs improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
bjubes committed May 1, 2023
1 parent 9b623c2 commit f0bb44e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ go get github.com/bjubes/config
```

2. Make your custom struct implements the `Configurator` interface using the following code (just copy and paste)
```go
```go
func (c MyConfig) GetEnvString(field string) string {
return config.GetEnvString(c, field)
}
Expand All @@ -39,10 +39,10 @@ go get github.com/bjubes/config
func (c MyConfig) GetEnvFloat(field string) float64 {
return config.GetEnvFloat(c, field)
}
```
```

3. Retrieve a value using the methods on your config instance
```go
```go
host := myConfig.GetEnvString("DB_HOST")
port := myConfig.GetEnvInt("DB_PORT")
prod := myConfig.GetEnvBool("PROD")
Expand Down
8 changes: 4 additions & 4 deletions configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Configurator interface {
}

// GetEnvString gets a string from the environment, falling back to the same field name in the config struct.
// If it doesn't exist in either, the function will log an error then exit 1
// If it doesn't exist in either, the function will log an error and panic
func GetEnvString(config Configurator, field string) string {
defer func() {
if r := recover(); r != nil {
Expand All @@ -34,7 +34,7 @@ func GetEnvString(config Configurator, field string) string {
}

// GetEnvBool gets a bool from the environment, falling back to the same field name in the config struct.
// If it doesn't exist in either, the function will log an error then exit 1
// If it doesn't exist in either, the function will log an error and panic
func GetEnvBool(config Configurator, field string) bool {
defer func() {
if r := recover(); r != nil {
Expand All @@ -52,7 +52,7 @@ func GetEnvBool(config Configurator, field string) bool {
}

// GetEnvInt gets an int from the environment, falling back to the same field name in the config struct.
// If it doesn't exist in either, the function will log an error then exit 1
// If it doesn't exist in either, the function will log an error and panic
func GetEnvInt(config Configurator, field string) int {
defer func() {
if r := recover(); r != nil {
Expand All @@ -70,7 +70,7 @@ func GetEnvInt(config Configurator, field string) int {
}

// GetEnvFloat gets a float from the environment, falling back to the same field name in the config struct.
// If it doesn't exist in either, the function will log an error then exit 1
// If it doesn't exist in either, the function will log an error and panic
func GetEnvFloat(config Configurator, field string) float64 {
defer func() {
if r := recover(); r != nil {
Expand Down

0 comments on commit f0bb44e

Please sign in to comment.