-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
64 lines (54 loc) · 1.36 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
59
60
61
62
63
64
package main
import (
"github.com/ZiRunHua/LeapLedger/initialize"
_ "github.com/ZiRunHua/LeapLedger/initialize/database"
"github.com/ZiRunHua/LeapLedger/router"
)
import (
"context"
"fmt"
"log"
"net/http"
"os"
"os/signal"
"syscall"
"time"
// Import "time/tzdata" for loading time zone data,
// so in order to make the binary files can be run independently,
// or in need of extra "$GOROOT/lib/time/zoneinfo.Zip" file, see time.LoadLocation
_ "time/tzdata"
)
var httpServer *http.Server
// @title LeapLedger API
// @version 1.0
// @contact.name ZiRunHua
// @license.name AGPL 3.0
// @license.url https://www.gnu.org/licenses/agpl-3.0.html
// @host localhost:8080
// @securityDefinitions.jwt Bearer
// @in header
// @name Authorization
func main() {
httpServer = &http.Server{
Addr: fmt.Sprintf(":%d", initialize.Config.System.Addr),
Handler: router.Engine,
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
MaxHeaderBytes: 1 << 20,
}
err := httpServer.ListenAndServe()
if err != nil {
panic(err)
}
shutDown()
}
func shutDown() {
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
log.Println("Shutting down server...")
if err := httpServer.Shutdown(context.TODO()); err != nil {
log.Fatal("Server forced to shutdown:", err)
}
log.Println("Server exiting")
}