Skip to content

Commit f8c77f5

Browse files
committed
Add config package docs
1 parent b39255d commit f8c77f5

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

config/config.go

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

346
import (

0 commit comments

Comments
 (0)