package main import ( "fmt" "strconv" "strings" "time" "git.giaever.org/joachimmg/go-ini.git/ini" ) type IniDate time.Time func (i IniDate) UnmarshalINI(b []byte) error { return nil } type TestUnm struct { myname string mydate int mymonth int myyear int } func (t *TestUnm) UnmarshalINI(b []byte) error { str := strings.Split(string(b), ",") if len(str) != 4 { return fmt.Errorf("must contain 4 entries, got %d", len(str)) } d, err := strconv.Atoi(str[1]) if err != nil { return err } m, err := strconv.Atoi(str[2]) if err != nil { return err } y, err := strconv.Atoi(str[3]) if err != nil { return err } t.myname = str[0] t.mydate = d t.mymonth = m t.myyear = y fmt.Println(str[0], d, m, y, t) return nil } type Test struct { String string UnquotedString string MultipleLines string WithoutValue bool AboutMe *TestUnm Date IniDate `ini:"date"` Int struct { Int int Int8 int8 Int16 int16 Int32 int32 Int64 int64 Uint struct { Uint uint Uint8 uint8 Uint16 uint16 Uint32 uint32 Uint64 uint64 } } } func main() { text := ` String = "This is some text" UnquotedString = This is some unquoted text MultipleLines = This is \ multiple lines \ going on WithoutValue AboutMe = joachim,23,09,85 [Int] Int = -1 Int8 = -8 Int16 = -16 Int32 = -32 Int64 = -64 [Int.Uint] Uint = 1 Uint8 = 8 Uint16 = 16 Uint32 = 32 Uint64 = 64 Uint64 = 64 ` fmt.Println("INI", text) test1 := &Test{} test2 := Test{ String: "This is some text", UnquotedString: "Helloooo... Not possible to not quote this", MultipleLines: "This is \nmultiple lines \ngoing on", WithoutValue: true, Date: IniDate(time.Now()), } test2.Int.Int = -1 test2.Int.Int8 = -8 test2.Int.Int16 = -16 test2.Int.Int32 = -32 test2.Int.Int64 = -64 test2.Int.Uint.Uint = 1 test2.Int.Uint.Uint8 = 8 test2.Int.Uint.Uint16 = 16 test2.Int.Uint.Uint32 = 32 test2.Int.Uint.Uint64 = 64 fmt.Println("Test1", test1) fmt.Println("Result", ini.Unmarshal([]byte(text), test1), test1, test1.AboutMe) //fmt.Println(ini.Marshal(test2)) }