doc.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Package goconf provides configuraton read and write implementations.
  3. Examples:
  4. package main
  5. import (
  6. "fmt"
  7. "github.com/Terry-Mao/goconf"
  8. "time"
  9. )
  10. type TestConfig struct {
  11. ID int `goconf:"core:id"`
  12. Col string `goconf:"core:col"`
  13. Ignore int `goconf:"-"`
  14. Arr []string `goconf:"core:arr:,"`
  15. Test time.Duration `goconf:"core:t_1:time"`
  16. Buf int `goconf:"core:buf:memory"`
  17. Arr1 []int `goconf:"core:arr1:,"`
  18. M map[int]string`goconf:"core:m:,"`
  19. }
  20. func main() {
  21. conf := goconf.New()
  22. if err := conf.Parse("./examples/conf_test.txt"); err != nil {
  23. panic(err)
  24. }
  25. core := conf.Get("core")
  26. if core == nil {
  27. panic("no core section")
  28. }
  29. id, err := core.Int("id")
  30. if err != nil {
  31. panic(err)
  32. }
  33. fmt.Println(id)
  34. tf := &TestConfig{}
  35. if err := conf.Unmarshal(tf); err != nil {
  36. panic(err)
  37. }
  38. fmt.Println(tf.ID)
  39. }
  40. */
  41. package goconf