/
internal_utils.go
52 lines (42 loc) · 1.03 KB
/
internal_utils.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
package config
import (
"time"
"golang.org/x/xerrors"
"github.com/saiya/dsps/server/domain"
)
func makeIntPtr(value int) *int {
return &value
}
func makeFloat64Ptr(value float64) *float64 {
return &value
}
func makeDuration(str string) domain.Duration {
d, err := time.ParseDuration(str)
if err != nil {
panic(xerrors.Errorf("makeDuration(\"%s\") resulted in %w", str, err))
}
return domain.Duration{Duration: d}
}
func makeDurationPtr(str string) *domain.Duration {
d := makeDuration(str)
return &d
}
func makeRegex(str string) *domain.Regex {
result, err := domain.NewRegex(str)
if err != nil {
panic(xerrors.Errorf("makeRegex(\"%s\") resulted in %w", str, err))
}
return result
}
func intMustBeLargerThanZero(name string, value int) error {
if value <= 0 {
return xerrors.Errorf("%s must not be negative nor zero", name)
}
return nil
}
func durationMustBeLargerThanZero(name string, d domain.Duration) error {
if d.Duration <= 0 {
return xerrors.Errorf("%s must not be negative nor zero", name)
}
return nil
}