forked from tleyden/elastic-thought
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configuration.go
82 lines (67 loc) · 2.09 KB
/
configuration.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package elasticthought
import (
"errors"
"fmt"
"github.com/couchbaselabs/logg"
"github.com/tleyden/go-couch"
)
type QueueType int
const (
Nsq QueueType = iota
Goroutine
)
// Holds configuration values that are used throughout the application
type Configuration struct {
DbUrl string
CbfsUrl string
NsqLookupdUrl string
NsqdUrl string
NsqdTopic string
WorkDirectory string
QueueType QueueType
NumCbfsClusterNodes int // needed to validate cbfs cluster health
}
func NewDefaultConfiguration() *Configuration {
config := &Configuration{
DbUrl: "http://localhost:4985/elastic-thought",
CbfsUrl: "file:///tmp",
NsqLookupdUrl: "127.0.0.1:4161",
NsqdUrl: "127.0.0.1:4150",
NsqdTopic: "elastic-thought",
WorkDirectory: "/tmp/elastic-thought",
QueueType: Goroutine,
NumCbfsClusterNodes: 1,
}
return config
}
// Connect to db based on url stored in config, or panic if not able to connect
func (c Configuration) DbConnection() couch.Database {
db, err := couch.Connect(c.DbUrl)
if err != nil {
err = errors.New(fmt.Sprintf("Error %v | dbUrl: %v", err, c.DbUrl))
logg.LogPanic("%v", err)
}
return db
}
// Create a new cbfs client based on url stored in config
func (c Configuration) NewBlobStoreClient() (BlobStore, error) {
return NewBlobStore(c.CbfsUrl)
}
// Add values from parsedDocOpts into Configuration and return a new instance
// Example map:
// map[--help:false --blob-store-url:file:///tmp --sync-gw-url:http://blah.com:4985/et]
func (c Configuration) Merge(parsedDocOpts map[string]interface{}) (Configuration, error) {
// Sync Gateway URL
syncGwUrl, ok := parsedDocOpts["--sync-gw-url"].(string)
if !ok {
return c, fmt.Errorf("Expected string arg in --sync-gw-url, got %T", syncGwUrl)
}
c.DbUrl = syncGwUrl
// Blob Store URL
blobStoreUrl, ok := parsedDocOpts["--blob-store-url"].(string)
if !ok {
return c, fmt.Errorf("Expected string arg in --blob-store-url, got %T", blobStoreUrl)
}
c.CbfsUrl = blobStoreUrl
return c, nil
}