-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconfig_helpers.go
More file actions
108 lines (98 loc) · 1.97 KB
/
config_helpers.go
File metadata and controls
108 lines (98 loc) · 1.97 KB
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
package main
import (
"encoding/json"
"errors"
"os"
"strings"
)
//go:fix inline
func float64Ptr(v float64) *float64 { return new(v) }
//go:fix inline
func intPtr(v int) *int { return new(v) }
func stringPtr(v string) *string {
if v == "" {
return nil
}
return &v
}
//go:fix inline
func boolPtr(v bool) *bool {
return new(v)
}
func filterAlphanumeric(s string) string {
var buf []byte
for i := 0; i < len(s); i++ {
b := s[i]
if (b >= 'a' && b <= 'z') || (b >= '0' && b <= '9') {
buf = append(buf, b)
} else if b >= 'A' && b <= 'Z' {
buf = append(buf, b+32) // lowercase
}
}
return string(buf)
}
func loadMinerTypeBlacklist(path string) ([]string, error) {
if strings.TrimSpace(path) == "" {
return nil, nil
}
data, err := os.ReadFile(path)
if err != nil {
if errors.Is(err, os.ErrNotExist) {
return nil, nil
}
return nil, err
}
var entries []string
if err := json.Unmarshal(data, &entries); err != nil {
return nil, err
}
if len(entries) == 0 {
return nil, nil
}
out := make([]string, 0, len(entries))
seen := make(map[string]struct{}, len(entries))
for _, entry := range entries {
trimmed := strings.TrimSpace(entry)
if trimmed == "" {
continue
}
key := strings.ToLower(trimmed)
if _, ok := seen[key]; ok {
continue
}
seen[key] = struct{}{}
out = append(out, trimmed)
}
if len(out) == 0 {
return nil, nil
}
return out, nil
}
func fileExists(path string) bool {
if path == "" {
return false
}
if _, err := os.Stat(path); err == nil {
return true
}
return false
}
func normalizeShareJobFreshnessMode(mode int) int {
switch mode {
case shareJobFreshnessOff, shareJobFreshnessJobID, shareJobFreshnessJobIDPrev:
return mode
default:
return -1
}
}
func shareJobFreshnessChecksJobID(mode int) bool {
switch mode {
case shareJobFreshnessJobID, shareJobFreshnessJobIDPrev:
return true
default:
return false
}
}
func shareJobFreshnessChecksPrevhash(mode int) bool {
return mode == shareJobFreshnessJobIDPrev
}