65 lines
1.4 KiB
Go
65 lines
1.4 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"runtime"
|
|
"time"
|
|
|
|
"myschools.me/suguo/gofound/global"
|
|
"myschools.me/suguo/search/exceptionless"
|
|
"myschools.me/suguo/search/model"
|
|
"myschools.me/suguo/search/mysql"
|
|
"myschools.me/suguo/search/service"
|
|
)
|
|
|
|
func main() {
|
|
// 日志初始化
|
|
exceptionless.Init(&exceptionless.Config{
|
|
ApiKey: os.Getenv("exceptionless_apikey"),
|
|
ServerURL: os.Getenv("exceptionless_url"),
|
|
})
|
|
|
|
//mysql初始化
|
|
mysql.Init(&mysql.Config{
|
|
ConnString: os.Getenv("mysql_dsn"),
|
|
ConnMaxLifetime: 1,
|
|
MaxIdleConns: 2,
|
|
MaxOpenConns: 300,
|
|
})
|
|
db, err := mysql.New()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
if err := db.AutoMigrate(&model.Site{}, &model.Domain{}, &model.SiteObj{}); err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
//搜索初始化
|
|
service.GoFoundInit(&global.Config{
|
|
Addr: "192.168.0.254:5678",
|
|
Data: os.Getenv("gofound_data"),
|
|
Debug: false,
|
|
Dictionary: os.Getenv("gofound_dictionary"),
|
|
EnableAdmin: true,
|
|
Gomaxprocs: runtime.NumCPU() * 2,
|
|
Shard: 0,
|
|
Auth: "",
|
|
EnableGzip: true,
|
|
Timeout: 10 * 60,
|
|
BufferNum: 0,
|
|
})
|
|
|
|
go service.Probe()
|
|
|
|
// 服务停止相应
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, os.Interrupt)
|
|
<-c
|
|
_, cancel := context.WithTimeout(context.Background(), 15*time.Second)
|
|
defer cancel()
|
|
exceptionless.SubmitLog("search service shutting down", "info")
|
|
os.Exit(0)
|
|
}
|