Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54dc982

Browse files
committed
参数支持方式修改
1 parent 81ae75f commit 54dc982

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

websites/code2/studygolang/src/global/app.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ const (
5555
)
5656

5757
func init() {
58-
if !flag.Parsed() {
59-
flag.Parse()
60-
}
61-
6258
App.Name = os.Args[0]
6359
App.Version = "V2.0.0"
6460
App.Build = Build
@@ -71,19 +67,23 @@ func init() {
7167
App.Date = fileInfo.ModTime()
7268

7369
App.Env = config.ConfigFile.MustValue("global", "env")
74-
75-
if showVersion != nil && *showVersion {
76-
PrintVersion(os.Stdout)
77-
os.Exit(0)
78-
}
7970
}
8071

8172
func PrintVersion(w io.Writer) {
73+
if !flag.Parsed() {
74+
flag.Parse()
75+
}
76+
77+
if showVersion == nil || !*showVersion {
78+
return
79+
}
80+
8281
fmt.Fprintf(w, "Binary: %s\n", App.Name)
8382
fmt.Fprintf(w, "Version: %s\n", App.Version)
8483
fmt.Fprintf(w, "Build: %s\n", App.Build)
8584
fmt.Fprintf(w, "Compile date: %s\n", App.Date.Format("2006-01-02 15:04:05"))
8685
fmt.Fprintf(w, "Env: %s\n", App.Env)
86+
os.Exit(0)
8787
}
8888

8989
func OnlineEnv() bool {

websites/code2/studygolang/src/logic/searcher.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ func (self SearcherLogic) Indexing(isAll bool) {
3737
self.IndexingArticle(isAll)
3838
self.IndexingTopic(isAll)
3939
self.IndexingResource(isAll)
40+
self.IndexingOpenProject(isAll)
4041
}
4142

4243
// IndexingArticle 索引博文
@@ -403,6 +404,8 @@ func (this *SolrClient) Post() error {
403404

404405
stringBuilder.Append("}")
405406

407+
logger.Infoln("start post data to solr...")
408+
406409
resp, err := http.Post(config.ConfigFile.MustValue("search", "engine_url")+"/update?wt=json&commit=true", "application/json", stringBuilder)
407410
if err != nil {
408411
logger.Errorln("post error:", err)
@@ -418,5 +421,7 @@ func (this *SolrClient) Post() error {
418421
return err
419422
}
420423

424+
logger.Infoln("post data result:", result)
425+
421426
return nil
422427
}

websites/code2/studygolang/src/server/indexer/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ var manualIndex = flag.Bool("manual", false, "do manual index once or not")
2323
func init() {
2424
// 设置随机数种子
2525
rand.Seed(time.Now().Unix())
26+
}
2627

28+
func main() {
2729
if !flag.Parsed() {
2830
flag.Parse()
2931
}
30-
}
3132

32-
func main() {
3333
logger.Init(ROOT+"/log", ConfigFile.MustValue("global", "log_level", "DEBUG"))
3434

3535
if *manualIndex {

websites/code2/studygolang/src/server/studygolang/main.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ func init() {
3939
}
4040

4141
func main() {
42+
// 支持根据参数打印版本信息
43+
global.PrintVersion(os.Stdout)
44+
4245
savePid()
4346

4447
logger.Init(ROOT+"/log", ConfigFile.MustValue("global", "log_level", "DEBUG"))

0 commit comments

Comments
 (0)