-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessage.go
More file actions
57 lines (48 loc) · 1.57 KB
/
Copy pathmessage.go
File metadata and controls
57 lines (48 loc) · 1.57 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
package netargv
// Message holds the parsed content of a single netargv frame.
// All fields are read-only after construction.
type Message struct {
verb string
args []string
flags FlagSet
payload []byte
raw []byte
}
func (m Message) Verb() string { return m.verb }
func (m Message) Args() []string { return m.args }
func (m Message) Flags() FlagSet { return m.flags }
func (m Message) Payload() []byte { return m.payload }
func (m Message) Raw() []byte { return m.raw }
// #####################################################################
// FlagSet
// #####################################################################
// FlagSet is the collection of named flags carried by a Message.
// A flag may appear multiple times; values accumulate in order.
type FlagSet map[string][]string
func (f FlagSet) Has(name string) bool {
_, ok := f[name]
return ok
}
// Get returns the first value for name, or "" if absent.
func (f FlagSet) Get(name string) string {
if vals, ok := f[name]; ok && len(vals) > 0 {
return vals[0]
}
return ""
}
// GetRepeated returns all values for name in declaration order.
func (f FlagSet) GetRepeated(name string) []string {
return f[name]
}
// Lookup returns the first value and true if the flag is present.
func (f FlagSet) Lookup(name string) (string, bool) {
if vals, ok := f[name]; ok && len(vals) > 0 {
return vals[0], true
}
return "", false
}
// LookupRepeated returns all values and true if the flag is present.
func (f FlagSet) LookupRepeated(name string) ([]string, bool) {
vals, ok := f[name]
return vals, ok
}