-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
92 lines (79 loc) · 2.81 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*GRP-GNU-AGPL******************************************************************
File: main.go
Copyright (C) 2021 Team Georepublic <info@georepublic.de>
Developer(s):
Copyright (C) 2021 Ashish Kumar <ashishkr23438@gmail.com>
-----
This file is part of pg_scheduleserv.
pg_scheduleserv is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published
by the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
pg_scheduleserv is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with pg_scheduleserv. If not, see <https://www.gnu.org/licenses/>.
******************************************************************GRP-GNU-AGPL*/
package main
import (
"context"
"fmt"
"os"
"runtime"
"strconv"
"strings"
"github.com/Georepublic/pg_scheduleserv/internal/api"
"github.com/Georepublic/pg_scheduleserv/internal/config"
"github.com/jackc/pgx/v4/pgxpool"
"github.com/sirupsen/logrus"
)
// @title pg_scheduleserv API
// @version 0.2.0
// @description This is an API for scheduling VRP tasks. Source code can be found on https://github.com/Georepublic/pg_scheduleserv
// @termsOfService https://swagger.io/terms/
// @contact.name Team Georepublic
// @contact.email info@georepublic.de
// @license.name GNU Affero General Public License
// @license.url https://www.gnu.org/licenses/agpl-3.0.en.html
// @host localhost:9100
// @BasePath /
// @accept application/json
// @produce application/json
// @schemes http https
func main() {
logrus.SetFormatter(&logrus.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05 -0700",
FullTimestamp: true,
CallerPrettyfier: func(frame *runtime.Frame) (string, string) {
s := strings.Split(frame.Function, ".")
funcname := s[len(s)-1] + "()"
s = strings.Split(frame.File, "pg_scheduleserv/")
filename := s[len(s)-1] + ":" + strconv.Itoa(frame.Line)
return funcname, filename
},
})
logrus.SetLevel(logrus.DebugLevel)
logrus.SetReportCaller(true)
config, err := config.LoadConfig(".")
if err != nil {
logrus.Error("Cannot load config:", err)
}
connectionURL := fmt.Sprintf(
"user=%s password=%s host=%s port=%s dbname=%s sslmode=disable",
config.DatabaseUser,
config.DatabasePassword,
config.DatabaseHost,
config.DatabasePort,
config.DatabaseName,
)
conn, err := pgxpool.Connect(context.Background(), connectionURL)
if err != nil {
fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
os.Exit(1)
}
defer conn.Close()
server := api.NewServer(conn)
logrus.Error(server.Start(config.ServerPort))
}