/
main.go
64 lines (54 loc) · 1.42 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 (
"context"
"net/http"
"os"
"os/signal"
"syscall"
"time"
"github.com/PromptPal/PromptPal/config"
"github.com/PromptPal/PromptPal/routes"
"github.com/PromptPal/PromptPal/schema"
"github.com/PromptPal/PromptPal/service"
"github.com/graph-gophers/graphql-go"
"github.com/sirupsen/logrus"
)
var GitCommit string
func main() {
config.SetupConfig(false)
service.InitDB()
startHTTPServer()
}
func startHTTPServer() {
publicDomain := config.GetRuntimeConfig().PublicDomain
w3 := service.NewWeb3Service()
o := service.NewOpenAIService()
hi := service.NewHashIDService()
var graphqlSchema = graphql.MustParseSchema(
schema.String(),
&schema.QueryResolver{},
)
schema.Setup(hi, o, w3)
h := routes.SetupGinRoutes(GitCommit, w3, o, hi, graphqlSchema)
server := &http.Server{
Addr: publicDomain,
Handler: h,
}
go func() {
if err := server.ListenAndServe(); err != nil && err != http.ErrServerClosed {
logrus.Fatalf("listen: %s\n", err)
}
}()
logrus.Infoln("PromptPal Server is running on: ", publicDomain)
quit := make(chan os.Signal, 1)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit
logrus.Println("Shutting down server...")
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
service.Close()
if err := server.Shutdown(ctx); err != nil {
logrus.Fatalln("Server forced to shutdown:", err)
}
logrus.Infoln("PromptPal Server exiting")
}