123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- 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))
- }
|