-
Notifications
You must be signed in to change notification settings - Fork 0
/
variation.go
51 lines (42 loc) · 1.09 KB
/
variation.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
49
50
51
package slots
import (
"encoding/json"
"errors"
"io/ioutil"
)
type Variation struct {
Slug string `json:"slug"`
Symbols []symbol `json:"symbols"`
Reels [][]int `json:"reels"`
Lines [][]int `json:"lines"`
}
type symbol struct {
Slug string `json:"slug"`
Payouts []float64 `json:"payouts"`
Wild bool `json:"wild"`
}
var (
errReadingConfigFile = errors.New("error reading config file")
errInvalidJson = errors.New("invalid json")
)
// NewVariationFromConfig reading file and returns variation struct.
func NewVariationFromConfig(file string) (*Variation, error) {
b, err := ioutil.ReadFile(file)
if err != nil {
return nil, errReadingConfigFile
}
variation := &Variation{}
err = json.Unmarshal([]byte(b), &variation)
if err != nil {
return nil, errInvalidJson
}
return variation, nil
}
// NewVariationFromString creating variation struct from string.
func NewVariationFromString(s string) (*Variation, error) {
variation := &Variation{}
if err := json.Unmarshal([]byte(s), &variation); err != nil {
return nil, errInvalidJson
}
return variation, nil
}