This repository was archived by the owner on Mar 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcc.go
More file actions
104 lines (85 loc) · 2.91 KB
/
cc.go
File metadata and controls
104 lines (85 loc) · 2.91 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
package cc
import "time"
// Configer is a abstraction for config.
type Configer interface {
KV() map[string]interface{}
Has(name string) bool
Must(name string)
Raw(name string) interface{}
Value(name string) Valuer
Config(name string) Configer
Pattern(name string) Patterner
SetDefault(name string, value interface{})
Set(name string, value interface{})
String(name string) string
StringOr(name string, deflt string) string
StringAnd(name string, pattern string) (string, bool)
StringAndOr(name string, pattern string, deflt string) string
Bool(name string) bool
BoolOr(name string, deflt bool) bool
Int(name string) int
IntOr(name string, deflt int) int
IntAnd(name string, pattern string) (int, bool)
IntAndOr(name string, pattern string, deflt int) int
Int64(name string) int64
Int64Or(name string, deflt int64) int64
Int64And(name string, pattern string) (int64, bool)
Int64AndOr(name string, pattern string, deflt int64) int64
Float(name string) float64
FloatOr(name string, deflt float64) float64
FloatAnd(name string, pattern string) (float64, bool)
FloatAndOr(name string, pattern string, deflt float64) float64
Duration(name string) time.Duration
DurationOr(name string, deflt int64) time.Duration
DurationAnd(name string, pattern string) (time.Duration, bool)
DurationAndOr(name string, pattern string, deflt int64) time.Duration
}
// Valuer is a abstraction for config value, which can convert into multiple types.
type Valuer interface {
Exist() bool
Raw() interface{}
Config() Configer
Pattern() Patterner
Map() map[string]Valuer
List() []Valuer
String() string
StringOr(deflt string) string
StringAnd(pattern string) (string, bool)
StringAndOr(pattern string, deflt string) string
Bool() bool
BoolOr(deflt bool) bool
Int() int
IntOr(deflt int) int
IntAnd(pattern string) (int, bool)
IntAndOr(pattern string, deflt int) int
Int64() int64
Int64Or(deflt int64) int64
Int64And(pattern string) (int64, bool)
Int64AndOr(pattern string, deflt int64) int64
Float() float64
FloatOr(deflt float64) float64
FloatAnd(pattern string) (float64, bool)
FloatAndOr(pattern string, deflt float64) float64
Duration() time.Duration
DurationOr(deflt int64) time.Duration
DurationAnd(pattern string) (time.Duration, bool)
DurationAndOr(pattern string, deflt int64) time.Duration
}
// Patterner is abstraction which do validation work.
// if pattern is not valid, then the following methods will always return false.
//
// string pattern use the native regular expression to validate the value.
//
// int(time.Duration) and float64 pattern use the basic if-like conditions to calculate and validate
// the value, use 'N' as placeholder for number, bit operation is not supported,
// for example:
// "N>2"
// "N>1&&N<=5"
// "N<1||N>3"
// "(N%2==0)&&(N<=4||N>=8)"
type Patterner interface {
Err() error
ValidateInt(n int) bool
ValidateFloat(n float64) bool
ValidateString(s string) bool
}