-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.go
62 lines (56 loc) · 1.71 KB
/
config.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
56
57
58
59
60
61
62
package ircb
import (
"encoding/json"
)
// Config holds configurable variables for ircb client
type Config struct {
Host string // in the form 'host:port'
Nick string
Master string // in the form 'master:prefix'
CommandPrefix string
Channels string // comma separated channels to autojoin
UseSSL bool
InvalidSSL bool
ParseLinks bool
Define bool
Verbose bool
Karma bool
Diamond bool // use diamond system
DiamondSocket string // path to socket
Database string // path to boltdb (can be empty to use bolt.db)
AuthMode int // 0 ACC (freenode, recommended), 1 STATUS, -1 none
}
// NewDefaultConfig returns the default config, minimal changes would be Host,Nick,Master for typical usage.
func NewDefaultConfig() *Config {
config := new(Config)
config.Host = "chat.freenode.net:6697"
config.Nick = "mustangsally"
config.Master = "aerth:$"
config.CommandPrefix = "!"
config.Channels = "##ircb,##go-nuts"
config.UseSSL = true
config.InvalidSSL = false
config.Karma = true
config.ParseLinks = false
config.Define = true
return config
}
// MarshalConfig encodes the connection's config as JSON
func (c *Connection) MarshalConfig() []byte {
b, _ := c.config.Marshal()
return b
}
// Marshal into json encoded bytes from config values
func (c Config) Marshal() ([]byte, error) {
return json.MarshalIndent(c, " ", " ")
}
// ConfigFromJSON loads a new config from json encoded bytes.
// It starts with a NewDefaultConfig, so not all fields must be present in json code.
func ConfigFromJSON(b []byte) (*Config, error) {
config := NewDefaultConfig()
err := json.Unmarshal(b, &config)
if err != nil {
return nil, err
}
return config, nil
}