-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathoper.go
More file actions
34 lines (28 loc) · 665 Bytes
/
oper.go
File metadata and controls
34 lines (28 loc) · 665 Bytes
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
package etcdircd
import (
"bytes"
"encoding/gob"
"strings"
)
type OperValue struct {
Pass string
Global bool
}
func (ov OperValue) Encode() string { return encodeOperValue(ov) }
func encodeOperValue(ov OperValue) string {
buf := bytes.NewBuffer(make([]byte, 0, 256))
enc := gob.NewEncoder(buf)
if err := enc.Encode(&ov); err != nil {
panic(err)
}
return buf.String()
}
func NewOperValue(ov string) (*OperValue, error) { return decodeOperValue(ov) }
func decodeOperValue(ov string) (*OperValue, error) {
dec := gob.NewDecoder(strings.NewReader(ov))
v := &OperValue{}
if err := dec.Decode(v); err != nil {
return nil, err
}
return v, nil
}