-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
68 lines (56 loc) · 1.64 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
63
64
65
66
67
68
package main
import (
"errors"
"github.com/codegangsta/cli"
)
type Config struct {
ctx *cli.Context
neoHost string
neoPort int
neoUsername string
neoPassword string
twitterConsumerKey string
twitterConsumerSecret string
twitterUserKey string
twitterUserSecret string
screenName string
}
func NewConfig(ctx *cli.Context) (*Config, error) {
cnf := &Config{
ctx: ctx,
}
cnf.neoHost = ctx.GlobalString("host")
if cnf.neoHost == "" {
return nil, errors.New("neo host is not defined")
}
cnf.neoPort = ctx.GlobalInt("port")
if cnf.neoPort == 0 {
return nil, errors.New("neo port is not defined")
}
cnf.twitterConsumerKey = ctx.GlobalString("consumer-key")
if cnf.twitterConsumerKey == "" {
return nil, errors.New("twitter consumer key is not defined")
}
cnf.twitterConsumerSecret = ctx.GlobalString("consumer-secret")
if cnf.twitterConsumerSecret == "" {
return nil, errors.New("twitter consumer secret is not defined")
}
cnf.twitterUserKey = ctx.GlobalString("user-key")
if cnf.twitterUserKey == "" {
return nil, errors.New("twitter user key is not defined")
}
cnf.twitterUserSecret = ctx.GlobalString("user-secret")
if cnf.twitterUserSecret == "" {
return nil, errors.New("twitter user secret is not defined")
}
cnf.neoUsername = ctx.GlobalString("user")
cnf.neoPassword = ctx.GlobalString("password")
return cnf, nil
}
func (p *Config) ScreenName() (string, error) {
p.screenName = p.ctx.GlobalString("screenname")
if p.screenName == "" {
return "", errors.New("twitter screen name is not defined")
}
return p.screenName, nil
}