changed server to use channels instead of cond for wakeup, removed config hashing, added config path to config struct
This commit is contained in:
@ -10,13 +10,16 @@ type Config struct {
|
||||
Groups map[string]*Group
|
||||
Alarms map[string]alarm.Alarm
|
||||
Interval time.Duration
|
||||
Hash string
|
||||
Listen string
|
||||
Path string
|
||||
}
|
||||
|
||||
func NewConfig() *Config {
|
||||
return &Config{
|
||||
// Default check interval, 30 seconds
|
||||
Interval: time.Second * 30,
|
||||
// Default listen address
|
||||
Listen: "127.0.0.1:8282",
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"git.binarythought.com/cdramey/alrm/alarm"
|
||||
"git.binarythought.com/cdramey/alrm/check"
|
||||
@ -30,6 +29,7 @@ type Parser struct {
|
||||
|
||||
func (p *Parser) Parse(fn string) (*Config, error) {
|
||||
config := NewConfig()
|
||||
config.Path = fn
|
||||
tok, err := NewTokenizer(fn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -70,6 +70,8 @@ func (p *Parser) Parse(fn string) (*Config, error) {
|
||||
fn, tok.Line(), value,
|
||||
)
|
||||
}
|
||||
case "listen":
|
||||
config.Listen = value
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown key for set in %s, line %d: \"%s\"",
|
||||
fn, tok.Line(), tk,
|
||||
@ -200,7 +202,6 @@ func (p *Parser) Parse(fn string) (*Config, error) {
|
||||
if err := tok.Err(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
config.Hash = hex.EncodeToString(tok.Hash.Sum(nil))
|
||||
return config, nil
|
||||
}
|
||||
|
||||
|
@ -2,9 +2,7 @@ package config
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"hash"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
@ -19,7 +17,6 @@ const (
|
||||
)
|
||||
|
||||
type Tokenizer struct {
|
||||
Hash hash.Hash
|
||||
curline int
|
||||
repline int
|
||||
file *os.File
|
||||
@ -36,7 +33,6 @@ func NewTokenizer(fn string) (*Tokenizer, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
tk.Hash = sha256.New()
|
||||
tk.reader = bufio.NewReader(tk.file)
|
||||
return tk, nil
|
||||
}
|
||||
@ -62,7 +58,6 @@ func (t *Tokenizer) Scan() bool {
|
||||
t.err = fmt.Errorf("invalid utf-8 encoding on line %s", t.repline)
|
||||
break
|
||||
}
|
||||
t.Hash.Write([]byte(string(r)))
|
||||
|
||||
switch state {
|
||||
case TK_NONE:
|
||||
|
Reference in New Issue
Block a user