-
Notifications
You must be signed in to change notification settings - Fork 1
/
daemon.go
145 lines (119 loc) · 2.67 KB
/
daemon.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2016, 2024 The TrueBlocks Authors. All rights reserved.
// Use of this source code is governed by a license that can
// be found in the LICENSE file.
/*
* Parts of this file were auto generated. Edit only those parts of
* the code inside of 'EXISTING_CODE' tags.
*/
package sdk
import (
// EXISTING_CODE
"encoding/json"
"fmt"
"strings"
"github.com/TrueBlocks/trueblocks-core/src/apps/chifra/pkg/output"
// EXISTING_CODE
)
type DaemonOptions struct {
Url string `json:"url,omitempty"`
Api DaemonApi `json:"api,omitempty"`
Scrape DaemonScrape `json:"scrape,omitempty"`
Monitor bool `json:"monitor,omitempty"`
Silent bool `json:"silent,omitempty"`
RenderCtx *output.RenderCtx `json:"-"`
Globals
}
// String implements the stringer interface
func (opts DaemonOptions) String() string {
bytes, _ := json.Marshal(opts)
return string(bytes)
}
type DaemonApi int
const (
NoDA DaemonApi = 0
DAOff = 1 << iota
DAOn
)
func (v DaemonApi) String() string {
switch v {
case NoDA:
return "none"
}
var m = map[DaemonApi]string{
DAOff: "off",
DAOn: "on",
}
var ret []string
for _, val := range []DaemonApi{DAOff, DAOn} {
if v&val != 0 {
ret = append(ret, m[val])
}
}
return strings.Join(ret, ",")
}
func enumFromDaemonApi(values []string) (DaemonApi, error) {
if len(values) == 0 {
return NoDA, fmt.Errorf("no value provided for api option")
}
var result DaemonApi
for _, val := range values {
switch val {
case "off":
result |= DAOff
case "on":
result |= DAOn
default:
return NoDA, fmt.Errorf("unknown api: %s", val)
}
}
return result, nil
}
type DaemonScrape int
const (
NoDS DaemonScrape = 0
DSOff = 1 << iota
DSBlooms
DSIndex
)
func (v DaemonScrape) String() string {
switch v {
case NoDS:
return "none"
}
var m = map[DaemonScrape]string{
DSOff: "off",
DSBlooms: "blooms",
DSIndex: "index",
}
var ret []string
for _, val := range []DaemonScrape{DSOff, DSBlooms, DSIndex} {
if v&val != 0 {
ret = append(ret, m[val])
}
}
return strings.Join(ret, ",")
}
func enumFromDaemonScrape(values []string) (DaemonScrape, error) {
if len(values) == 0 {
return NoDS, fmt.Errorf("no value provided for scrape option")
}
var result DaemonScrape
for _, val := range values {
switch val {
case "off":
result |= DSOff
case "blooms":
result |= DSBlooms
case "index":
result |= DSIndex
default:
return NoDS, fmt.Errorf("unknown scrape: %s", val)
}
}
return result, nil
}
// EXISTING_CODE
func (opts *DaemonOptions) ToInternal() *daemonOptionsInternal {
return opts.toInternal()
}
// EXISTING_CODE