-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
58 lines (48 loc) · 1.23 KB
/
main.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
/*
* 纸喵软件
* Copyright (c) 2017~2021 http://zhimiaox.cn All rights reserved.
* Author: 倒霉狐狸 <[email protected]>
* Date: 2021/11/24 下午10:00
*/
package main
import (
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/zhimiaox/go-api-layout/api"
"github.com/zhimiaox/go-api-layout/source"
"github.com/jinzhu/configor"
"github.com/sirupsen/logrus"
)
// @title 纸喵 API
// @version 1.0
// @description 纸喵软件系列
// @termsOfService http://zhimiao.org
// @contact.name API Support
// @contact.url http://tools.zhimiao.org
// @contact.email [email protected]
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @schemes http https
// @BasePath /api
// @securityDefinitions.apikey ApiAuth
// @in header
// @name Authorization
func main() {
if err := configor.Load(&source.Config, "config.toml"); err != nil {
panic(err)
}
http.DefaultClient.Timeout = time.Minute
go api.Start()
logrus.Infoln("signal received, server closed. ", waitForSignal())
}
func waitForSignal() os.Signal {
signalChan := make(chan os.Signal, 1)
defer close(signalChan)
signal.Notify(signalChan, syscall.SIGTERM, syscall.SIGINT)
s := <-signalChan
signal.Stop(signalChan)
return s
}