/
ScenarioConfig.go
79 lines (61 loc) · 1.58 KB
/
ScenarioConfig.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright (c) 2019 Australian Rivers Institute.
package data
import "github.com/LindsayBradford/crem/internal/pkg/config/data"
type ScenarioConfig struct {
Name string
RunNumber uint64
MaximumConcurrentRunNumber uint64
OutputPath string
OutputType ScenarioOutputType
OutputLevel ScenarioOutputLevel
CpuProfilePath string
Reporting ReportingConfig
UserDetail map[string]interface{}
}
type ScenarioOutputType struct {
value string
}
func (sot *ScenarioOutputType) String() string {
return sot.value
}
var (
CsvOutput = ScenarioOutputType{"CSV"}
JsonOutput = ScenarioOutputType{"JSON"}
ExcelOutput = ScenarioOutputType{"EXCEL"}
)
func (sot *ScenarioOutputType) UnmarshalText(text []byte) error {
context := data.UnmarshalContext{
ConfigKey: "OutputType",
ValidValues: []string{
CsvOutput.value, JsonOutput.value, ExcelOutput.value,
},
TextToValidate: string(text),
AssignmentFunction: func() {
sot.value = string(text)
},
}
return data.ProcessUnmarshalContext(context)
}
type ScenarioOutputLevel struct {
value string
}
func (sol *ScenarioOutputLevel) String() string {
return sol.value
}
var (
SummaryLevel = ScenarioOutputLevel{"Summary"}
DetailLevel = ScenarioOutputLevel{"Detail"}
)
func (sol *ScenarioOutputLevel) UnmarshalText(text []byte) error {
context := data.UnmarshalContext{
ConfigKey: "OutputLevel",
ValidValues: []string{
SummaryLevel.value, DetailLevel.value,
},
TextToValidate: string(text),
AssignmentFunction: func() {
sol.value = string(text)
},
}
return data.ProcessUnmarshalContext(context)
}