You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 1.2 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. go-ini
  2. ======
  3. INI parsing library for Go (golang).
  4. View the API documentation [here](http://godoc.org/github.com/vaughan0/go-ini).
  5. Usage
  6. -----
  7. Parse an INI file:
  8. ```go
  9. import "github.com/vaughan0/go-ini"
  10. file, err := ini.LoadFile("myfile.ini")
  11. ```
  12. Get data from the parsed file:
  13. ```go
  14. name, ok := file.Get("person", "name")
  15. if !ok {
  16. panic("'name' variable missing from 'person' section")
  17. }
  18. ```
  19. Iterate through values in a section:
  20. ```go
  21. for key, value := range file["mysection"] {
  22. fmt.Printf("%s => %s\n", key, value)
  23. }
  24. ```
  25. Iterate through sections in a file:
  26. ```go
  27. for name, section := range file {
  28. fmt.Printf("Section name: %s\n", name)
  29. }
  30. ```
  31. File Format
  32. -----------
  33. INI files are parsed by go-ini line-by-line. Each line may be one of the following:
  34. * A section definition: [section-name]
  35. * A property: key = value
  36. * A comment: #blahblah _or_ ;blahblah
  37. * Blank. The line will be ignored.
  38. Properties defined before any section headers are placed in the default section, which has
  39. the empty string as it's key.
  40. Example:
  41. ```ini
  42. # I am a comment
  43. ; So am I!
  44. [apples]
  45. colour = red or green
  46. shape = applish
  47. [oranges]
  48. shape = square
  49. colour = blue
  50. ```