Skip to content

Commit

Permalink
refactor: Simplifying config parsing
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Boutour <bob@vibioh.fr>
  • Loading branch information
ViBiOh committed Apr 27, 2024
1 parent 6017955 commit ddb4d8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
7 changes: 1 addition & 6 deletions cmd/goweb/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"context"
"fmt"
"log"
"net/http"

_ "net/http/pprof"
Expand All @@ -18,11 +17,7 @@ import (
)

func main() {
config, err := newConfig()
if err != nil {
log.Fatal(fmt.Errorf("config: %s", err))
}

config := newConfig()
alcotest.DoAndExit(config.alcotest)

go func() {
Expand Down
10 changes: 7 additions & 3 deletions cmd/goweb/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ type configuration struct {
health *health.Config
}

func newConfig() (configuration, error) {
func newConfig() configuration {
fs := flag.NewFlagSet("api", flag.ExitOnError)
fs.Usage = flags.Usage(fs)

return configuration{
config := configuration{
appServer: server.Flags(fs, ""),
health: health.Flags(fs, ""),
alcotest: alcotest.Flags(fs, ""),
Expand All @@ -40,5 +40,9 @@ func newConfig() (configuration, error) {
cors: cors.Flags(fs, "cors"),

hello: hello.Flags(fs, ""),
}, fs.Parse(os.Args[1:])
}

_ = fs.Parse(os.Args[1:])

return config
}

0 comments on commit ddb4d8b

Please sign in to comment.