-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoini.go
48 lines (40 loc) · 1.07 KB
/
goini.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//
// Created by WestleyR <[email protected]> on Nov 20, 2021
// Source code: https://github.com/WestleyR/goini
// https://github.com/WildWest-Productions/goini
//
// Copyright (c) 2021 WestleyR. All rights reserved.
// This software is licensed under a BSD 3-Clause Clear License.
// Consult the LICENSE file that came with this software regarding
// your rights to distribute this software.
//
package goini
import (
"fmt"
"reflect"
"github.com/wildwest-productions/goini/internal/pkg/parser"
)
func Unmarshal(iniData []byte, s interface{}) error {
t := reflect.ValueOf(s)
if t.Kind() == reflect.Ptr {
t = t.Elem()
}
if t.Kind() == reflect.Ptr {
t = t.Elem()
}
if t.Kind() != reflect.Struct {
return fmt.Errorf("not a struct")
}
iniTags := parser.GetIniTags(iniData)
return parser.Unmarshal(s, t, iniTags, "")
}
func Marshal(s interface{}) ([]byte, error) {
t := reflect.ValueOf(s)
if t.Kind() == reflect.Ptr {
t = t.Elem()
}
if t.Kind() != reflect.Struct {
return []byte{}, fmt.Errorf("not a struct")
}
return parser.MarshalValue(t)
}