123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- package main
- import (
- "fmt"
- "git.giaever.org/joachimmg/go-ini.git/ini"
- "strings"
- "time"
- )
- type Test struct {
- Str string `ini:"String"`
- UnquotedString string
- MultipleLines string
- WithoutValue bool
- Date ini.Date
- Time ini.Time
- TestTime time.Time
- IP ini.IP
- Int struct {
- Int int
- Int8 int8
- Int16 int16
- Int32 int32
- Int64 int64
- Uint struct {
- Uint uint
- Uint8 uint8
- Uint16 uint16
- Uint32 uint32
- Uint64 uint64
- }
- }
- Float struct {
- Float32 float32
- Float64 float64
- }
- }
- func (t *Test) String() string {
- return fmt.Sprintf(`
- STRUCT DATA:
- Str: %v
- UnquotedString: %v
- MultipleLines: %v
- WithoutValue: %v
- Date: %v
- Time: %v
- TestTime: %v
- IP: %v
- Int {
- Int: %v
- Int8: %v
- Int16: %v
- Int32: %v
- Int64: %v
- Uint {
- Uint: %v
- Uint8: %v
- Uint16: %v
- Uint32: %v
- Uint64: %v
- }
- }
- Float {
- Float32: %v
- Float64: %v
- }`,
- t.Str, t.UnquotedString, strings.Replace(t.MultipleLines, "\n", "\n\t\t\t\t", -1), t.WithoutValue, t.Date, t.Time, t.TestTime, t.IP,
- t.Int.Int, t.Int.Int8, t.Int.Int16, t.Int.Int32, t.Int.Int64,
- t.Int.Uint.Uint, t.Int.Uint.Uint8, t.Int.Uint.Uint16, t.Int.Uint.Uint32, t.Int.Uint.Uint64,
- t.Float.Float32, t.Float.Float64,
- )
- }
- func sep(f, e string) {
- var s []byte
- for i := 0; i < 80; i++ {
- s = append(s, '/')
- }
- fmt.Println(f, string(s), e)
- }
- func main() {
- text := `
- String = "This is some text"
- UnquotedString = This is some unquoted text
- MultipleLines = This is \
- multiple lines \
- going on
- WithoutValue
- Date = 2017-9-28-Local-0
- Time = 01 Jan 01 00:00 UTC
- IP = ::
- [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
- [Float]
- Float32 = 3.14722354762387648273648726348
- Float64 = 10.00003423472342734897234872347293748`
- first := &Test{}
- sep("", "")
- fmt.Println(" ### INI TO UNMARSHAL:")
- sep("", "")
- fmt.Println(text)
- sep("\n", "")
- fmt.Println(" ### INITIAL STRUCT VALUES (empty/unset values):")
- sep("", "")
- fmt.Println(first)
- sep("\n", "")
- fmt.Println(" --- NOW MARSHALING: INI -> STRUCT ---")
- err := ini.Unmarshal([]byte(text), first)
- fmt.Println(" !!! ERROR ON UMARSHALING:", err)
- sep("", "")
- fmt.Println(" ### NEW STRUCT VALUES (unmarshaled from INI):")
- sep("", "\n")
- fmt.Println(first)
- sep("\n", "")
- fmt.Println(" --- NOW UNMARSHALING: STRUCT -> INI ---")
- unm, err := ini.Marshal(first)
- fmt.Println(" !!! ERROR ON MARCHALING:", err)
- sep("", "")
- fmt.Println(" ### PRODUCED INI (marshaled from STRUCT)")
- sep("", "")
- fmt.Println(string(unm))
- sep("", "")
- }
|