-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutil.go
55 lines (49 loc) · 1 KB
/
util.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
53
54
55
package main
import (
"io/ioutil"
"math/rand"
"gopkg.in/yaml.v2"
)
func RandomBytes(n int) ([]byte, error) {
buf := make([]byte, n)
_, err := rand.Read(buf)
if err != nil {
return []byte{}, err
}
return buf, nil
}
// Create or validate a checksum.
// To create checksum:
//
// >>> c = checksum(b'...')
//
// To validate checksum against `c`:
//
// >>> checksum(b'...', c) == 0
//
// Note: The checksum is valid if it returns 0.
func Checksum(data []byte, chk int) int {
for _, b := range data {
chk ^= int(b)
}
return chk
}
type Config struct {
Host string `yaml:"host"`
Publishers []string `yaml:"publishers"`
Subscribers []string `yaml:"subscribers"`
Services []string `yaml:"services"`
ServiceListeners []string `yaml:"service_listeners"`
}
func loadConf(file string) Config {
config_bytes, err := ioutil.ReadFile(file)
if err != nil {
panic(err)
}
var conf Config
err = yaml.Unmarshal(config_bytes, &conf)
if err != nil {
panic(err)
}
return conf
}