-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigs.go
75 lines (67 loc) · 1.51 KB
/
configs.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
package main
import (
"fmt"
"os"
)
type MongoDsn struct {
Host string
Port string
Db string
User string
Pass string
}
func (dsn *MongoDsn) init() {
var ok bool
dsn.Host, ok = os.LookupEnv("MONGOHOST")
if !ok {
dsn.Host = "localhost"
}
dsn.Port, ok = os.LookupEnv("MONGOPORT")
if !ok {
dsn.Port = "27017"
}
dsn.Db, ok = os.LookupEnv("MONGODB")
if !ok {
dsn.Db = "uploads"
}
dsn.User = os.Getenv("MONGOUSER")
dsn.Pass = os.Getenv("MONGOPASS")
}
func (dsn *MongoDsn) buildDsn() string {
var mongoStr string
if dsn.User != "" && dsn.Pass != "" {
mongoStr = fmt.Sprintf("mongodb://%s:%s@%s:%s/%s", dsn.User, dsn.Pass, dsn.Host, dsn.Port, dsn.Db)
} else {
mongoStr = fmt.Sprintf("mongodb://%s:%s/%s", dsn.Host, dsn.Port, dsn.Db)
}
return mongoStr
}
type BucketInfo struct {
bucketName string
Project string
Environment string
Prefix string
}
func (info *BucketInfo) checkParams() {
if info.bucketName == "img_backet" {
fmt.Println("You need to set bucket name with parameter -bucket")
os.Exit(1)
}
if info.Project == "project_name" {
fmt.Println("You need to set project name with parameter -project")
os.Exit(1)
}
if info.Environment == "stage1" {
fmt.Println("You need to set env name with parameter -env")
os.Exit(1)
}
}
type CommonOptions struct {
version bool
}
func (opts *CommonOptions) checkParams() {
if opts.version {
fmt.Printf("Git Repo: %s\nGit Commit Hash: %s\nVersion: %s\nBuild Date: %s\n", gitRepo, gitCommit, appVersion, buildStamp)
os.Exit(0)
}
}