This is a creation in Article, where the information may have evolved or changed.
Website
Https://github.com/larspensjo/config
Sample code
Package main import ("FMT" "StrConv" "Github.com/robfig/config") type Student struct {name string age int }const (cfg_fie_name = "students.cfg" SECTION1 = "Student 1" SECTION2 = "section 2" option_name = "NAME" Option_age = "Age") func foo () {c: = config. Newdefault () Tom: = student{"Tom", 5} Jerry: = student{"Jerry", 6} c.addsection (SECTION1) c.addoption (SECTION1 , Option_name, Tom.name) c.addoption (SECTION1, Option_age, StrConv. Itoa (Tom.age)) c.addsection (SECTION2) c.addoption (SECTION2, option_name, Jerry.name) c.addoption (SECTION2, OPTION _age, StrConv. Itoa (Jerry.age)) C.writefile (Cfg_fie_name, 0644, "all the students") FMT. Println ("Done")}func Bar () {c, err: = config. Readdefault (cfg_fie_name) if err! = Nil {fmt. PRINTLN ("Read error:", err) return} FMT. Println ("Read Student 1 ...") Name, err: = C.string (SECTION1, option_name) if err! = Nil {fmt. Println ("Get name failed:", err) return} age, err: = C.int (SECTION1, option_age) if err! = Nil {fmt. Println ("Get Age failed:", err) return} FMT. Println ("Student 1:", Name, ",", age) fmt. Println ("Read Student 2 ...") Name, err = c.string (SECTION2, option_name) if err! = Nil {fmt. Println ("Get name failed:", err) return} age, err = C.int (SECTION2, option_age) if err! = nil {f Mt. Println ("Get Age failed:", err) return} FMT. Println ("Student 2:", Name, ",", age)}func main () {foo () bar ()}
INI file
# All the students[Student 1]Name: TomAge: 5[Section 2]Name: JerryAge: 6
Run results
$ go run main.goDone Read student 1...Student 1: Tom , 5Read student 2...Student 2: Jerry , 6$
More detailed information
More functions can be directly consulted source code.