forked from albrow/jobs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
55 lines (50 loc) · 1.49 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
// Copyright 2015 Alex Browne. All rights reserved.
// Use of this source code is governed by the MIT
// license, which can be found in the LICENSE file.
package jobs
// configType holds different config variables
type configType struct {
Db databaseConfig
envPrefix string
}
// databaseConfig holds config variables specific to the database
type databaseConfig struct {
Address string
Network string
Database int
Password string
}
// Config is where all configuration variables are stored. You may modify Config
// directly in order to change config variables, and should only do so at the start
// of your program.
var Config = configType{
Db: databaseConfig{
// Address is the address of the redis database to connect to. Default is
// "localhost:6379".
Address: "localhost:6379",
// Network is the type of network to use to connect to the redis database
// Default is "tcp".
Network: "tcp",
// Database is the redis database number to use for storing all data. Default
// is 0.
Database: 0,
// Password is a password to use for connecting to a redis database via the
// AUTH command. If empty, Jobs will not attempt to authenticate. Default is
// "" (an empty string).
Password: "",
},
envPrefix: "",
}
func (c *configType) SetEnvPrefix(p string) {
if p == "" {
return
}
c.envPrefix = p
}
func (c *configType) GetKeyPrefix() string {
var hardCodedPrefix = "jobs:"
if c.envPrefix == "" {
return hardCodedPrefix
}
return c.envPrefix + ":" + hardCodedPrefix
}