-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
74 lines (62 loc) · 1.79 KB
/
Copy pathmain.go
File metadata and controls
74 lines (62 loc) · 1.79 KB
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
// Copyright 2019 Melvin Davis<hi@melvindavis.me>. All rights reserved.
// Use of this source code is governed by a Melvin Davis<hi@melvindavis.me>
// license that can be found in the LICENSE file.
//Auth Server Auth Service provides the authentication for the cuttle.ai platform
package main
import (
"context"
"net/http"
"os"
"os/signal"
_ "github.com/jinzhu/gorm/dialects/postgres"
"github.com/cuttle-ai/auth-service/config"
"github.com/cuttle-ai/auth-service/log"
"github.com/cuttle-ai/auth-service/routes"
_ "github.com/cuttle-ai/auth-service/oauth/google"
_ "github.com/cuttle-ai/auth-service/routes/auth"
)
/*
* This file contains the main start point of the application
*/
func main() {
/*
* Create a new Server mux
* Create a default server
* Init the routes
* Now listen and serve
* Listen to the os signals for exit
* Graceful exit when command comes
*/
//creating a new server mux
m := http.NewServeMux()
//created the default server
s := &http.Server{
Addr: ":" + config.Port,
Handler: m,
ReadTimeout: config.RequestRTimeout,
WriteTimeout: config.ResponseWTimeout,
MaxHeaderBytes: 1 << 20,
}
//inited the routes
routes.InitRoutes(m)
//listen and serve to the server
go func() {
log.Info("Starting the server at :" + config.Port)
log.Error(s.ListenAndServe())
}()
go func() {
log.Info("Starting the rpc service at :" + config.RPCPort)
config.StartRPC()
}()
//listening for syscalls
var gracefulStop = make(chan os.Signal, 1)
signal.Notify(gracefulStop, os.Interrupt)
sig := <-gracefulStop
//gracefulling exiting when request comes in
log.Info("Received the interrupt", sig)
log.Info("Shutting down the server")
err := s.Shutdown(context.Background())
if err != nil {
log.Error("Couldn't end the server gracefully")
}
}