Avatar ·

How to properly work with configuration in Go: ENV, JSON, YAML or flags?

Hello everyone! I'm a beginner Go developer, writing my first microservice for order processing. I've run into a problem: I can't figure out how to properly organize the storage of configuration parameters (server port, database connection string, external API URL, timeouts, etc.).\n\nRight now I've just hardcoded everything in main.go:\n\n```go\npackage main\n\nimport (\n "fmt"\n "net/http"\n)\n\nfunc main() {\n port := ":8080"\n dbConn := "postgres://user:pass@localhost:5432/orders?sslmode=disable"\n apiURL := "https://api.example.com"\n \n fmt.Println("Starting server on", port)\n http.ListenAndServe(port, nil)\n}\n```\n\nI understand this is terrible: when changing environments (dev/staging/prod) you need to recompile the binary, and having passwords in code is a complete security disaster. I've seen that