Skip to content

Commit 2b091b6

Browse files
committed
Add config package docs
1 parent b265b72 commit 2b091b6

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

config/config.go

+50
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,53 @@
1+
// Package config provides utilities for configuration parsing and loading.
2+
// It provides functionality for parsing command-line flags and loading configuration from YAML files,
3+
// with additional support for setting default values and validation.
4+
//
5+
// The package includes the following main components:
6+
//
7+
// - [ParseFlags] function for parsing command-line flags.
8+
// - [FromYAMLFile] function for loading configuration settings from a YAML file,
9+
// with additional support for setting default values and validation.
10+
// - [TLS] struct representing configuration for a TLS client which
11+
// can be assembled to [crypto/tls.Config].
12+
//
13+
// Example usage:
14+
//
15+
// type Config struct {
16+
// ServerAddress string `yaml:"server_address" default:"localhost:8080"`
17+
// TLS config.TLS `yaml:",inline"`
18+
// }
19+
//
20+
// // Validate implements the Validator interface.
21+
// func (c *Config) Validate() error {
22+
// if _, _, err := net.SplitHostPort(c.ServerAddress); err != nil {
23+
// return errors.Wrapf(err, "invalid server address: %s", c.ServerAddress)
24+
// }
25+
//
26+
// return nil
27+
// }
28+
//
29+
// type Flags struct {
30+
// Config string `short:"c" long:"config" description:"Path to config file" required:"true"`
31+
// }
32+
//
33+
// func main() {
34+
// var flags Flags
35+
// if err := config.ParseFlags(&flags); err != nil {
36+
// log.Fatalf("error parsing flags: %v", err)
37+
// }
38+
//
39+
// var cfg Config
40+
// if err := config.FromYAMLFile(flags.Config, &cfg); err != nil {
41+
// log.Fatalf("error loading config: %v", err)
42+
// }
43+
//
44+
// tlsCfg, err := cfg.TLS.MakeConfig("icinga.com")
45+
// if err != nil {
46+
// log.Fatalf("error creating TLS config: %v", err)
47+
// }
48+
//
49+
// // ...
50+
// }
151
package config
252

353
import (

0 commit comments

Comments
 (0)