testini.go 526 B

123456789101112131415161718192021222324252627282930
  1. package main
  2. import (
  3. "gopkg.in/ini.v1"
  4. "log"
  5. )
  6. type IP struct {
  7. Value []string `ini:"value"`
  8. }
  9. func main() {
  10. iniconf := `[IP]
  11. value = 192.168.31.201
  12. value = 192.168.31.211
  13. value = 192.168.31.221`
  14. cfg, err := ini.ShadowLoad([]byte(iniconf))
  15. if err != nil {
  16. log.Fatal(err)
  17. }
  18. note := new(IP)
  19. for _, section := range cfg.Sections() {
  20. if err = section.MapTo(note);err != nil {
  21. log.Println(err)
  22. } else {
  23. log.Println(section.Name(), note.Value)
  24. }
  25. }
  26. }