-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathconfigs.go
164 lines (122 loc) · 3.73 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Package configs define and load all configurations. It depends on no othe GCSE packages.
package configs
import (
"log"
"os"
"time"
"github.com/golangplus/strings"
"github.com/daviddengcn/gcse/utils"
"github.com/daviddengcn/go-easybi"
"github.com/daviddengcn/go-ljson-conf"
"github.com/daviddengcn/go-villa"
"github.com/daviddengcn/sophie"
)
const (
fnCrawlerDB = "crawler"
fnToCrawl = "tocrawl"
FnPackage = "package"
FnPerson = "person"
// key: RawString, value: DocInfo
FnDocs = "docs"
FnNewDocs = "newdocs"
FnStore = "store"
)
var (
ServerAddr = ":8080"
ServerRoot = villa.Path("./service/web")
LoadTemplatePass = ""
AutoLoadTemplate = false
DataRoot = villa.Path("./data/")
// producer: server, consumer: crawler
ImportPath villa.Path
// producer: crawler, consumer: indexer
DBOutPath villa.Path
// configures of crawler
CrawlByGodocApi = true
CrawlGithubUpdate = true
CrawlerDuePerRun = 1 * time.Hour
CrawlerGithubClientID = ""
CrawlerGithubClientSecret = ""
CrawlerGithubPersonal = ""
BiWebPath = "/bi"
NonCrawlHosts = stringsp.Set{}
NonStorePackageRegexps = []string{}
StoreDAddr = ":8081"
LogDir = "/tmp"
)
func init() {
log.SetFlags(log.Flags() | log.Lshortfile)
conf, err := ljconf.Load("conf.json")
if err != nil {
// we must make sure configuration exist
log.Fatal(err)
}
ServerAddr = conf.String("web.addr", ServerAddr)
ServerRoot = conf.Path("web.root", ServerRoot)
LoadTemplatePass = conf.String("web.loadtemplatepass", LoadTemplatePass)
AutoLoadTemplate = conf.Bool("web.autoloadtemplate", AutoLoadTemplate)
DataRoot = conf.Path("back.dbroot", DataRoot)
ImportPath = DataRoot.Join("imports")
ImportPath.MkdirAll(0755)
DBOutPath = DataRoot.Join("dbout")
DBOutPath.MkdirAll(0755)
CrawlByGodocApi = conf.Bool("crawler.godoc", CrawlByGodocApi)
CrawlGithubUpdate = conf.Bool("crawler.github_update", CrawlGithubUpdate)
CrawlerDuePerRun = conf.Duration("crawler.due_per_run", CrawlerDuePerRun)
ncHosts := conf.StringList("crawler.noncrawl_hosts", nil)
NonCrawlHosts.Add(ncHosts...)
CrawlerGithubClientID = conf.String("crawler.github.clientid", "")
CrawlerGithubClientSecret = conf.String("crawler.github.clientsecret", "")
CrawlerGithubPersonal = conf.String("crawler.github.personal", "")
NonStorePackageRegexps = conf.StringList("docdb.nonstore_regexps", nil)
bi.DataPath = conf.String("bi.data_path", "/tmp/gcse.bolt")
BiWebPath = conf.String("bi.web_path", BiWebPath)
StoreDAddr = conf.String("stored.addr", StoreDAddr)
LogDir = conf.String("log.dir", LogDir)
}
func DataRootFsPath() sophie.FsPath {
return sophie.LocalFsPath(DataRoot.S())
}
func CrawlerDBPath() villa.Path {
return DataRoot.Join(fnCrawlerDB)
}
func CrawlerDBFsPath() sophie.FsPath {
return DataRootFsPath().Join(fnCrawlerDB)
}
func DocsDBPath() string {
return DataRoot.Join(FnDocs).S()
}
func DocsDBFsPath() sophie.FsPath {
return DataRootFsPath().Join(FnDocs)
}
func ToCrawlPath() string {
return DataRoot.Join(fnToCrawl).S()
}
func ToCrawlFsPath() sophie.FsPath {
return DataRootFsPath().Join(fnToCrawl)
}
func IndexPath() villa.Path {
return DataRoot.Join("index")
}
func StoreBoltPath() string {
return DataRoot.Join("store.bolt").S()
}
func FileCacheBoltPath() string {
return DataRoot.Join("filecache.bolt").S()
}
func SetTestingDataPath() {
DataRoot = villa.Path(os.TempDir()).Join("gcse_testing")
DataRoot.RemoveAll()
DataRoot.MkdirAll(0755)
log.Printf("DataRoot: %v", DataRoot)
}
// Returns the segments imported from web site.
func ImportSegments() utils.Segments {
return utils.Segments(ImportPath)
}
func DBOutSegments() utils.Segments {
return utils.Segments(DBOutPath)
}
func IndexSegments() utils.Segments {
return utils.Segments(IndexPath())
}