-
Notifications
You must be signed in to change notification settings - Fork 44
/
coder.go
40 lines (32 loc) · 812 Bytes
/
coder.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
package cli
// Decoder represents an interface which decodes string
type Decoder interface {
Decode(s string) error
}
// SliceDecoder represents an interface which decodes string as slice
type SliceDecoder interface {
Decoder
DecodeSlice()
}
// Encoder represents an interface which encodes to string
type Encoder interface {
Encode() string
}
// CounterDecoder represents an counter decoder
type CounterDecoder interface {
Decoder
IsCounter()
}
// Counter implements counter decoder
type Counter struct {
value int
}
// Value returns value of counter
func (c Counter) Value() int { return c.value }
// Decode decodes counter from string
func (c *Counter) Decode(s string) error {
c.value++
return nil
}
// IsCounter implements method of interface CounterDecoder
func (c Counter) IsCounter() {}