-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
63 lines (47 loc) · 1.26 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
package main
import (
"fmt"
"log"
"os"
"github.com/joho/godotenv"
"github.com/sreehari2003/kseb/auth"
"github.com/sreehari2003/kseb/controller"
"github.com/sreehari2003/kseb/db"
"github.com/sreehari2003/kseb/router"
)
// @title KSEB Web Server
// @version 1.0
// @description Provide Info About KSEB Web Server].
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name MIT
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost:8000
// @BasePath /api/v1
// @schemes http
func main() {
if _, exists := os.LookupEnv("RAILWAY_ENVIRONMENT"); !exists {
if err := godotenv.Load(); err != nil {
log.Fatal("error loading .env file:", err)
}
}
auth.Init()
PORT := os.Getenv("PORT")
host := "localhost"
env := os.Getenv("ENV")
if env != "DEVELOPMENT" {
host = "0.0.0.0"
}
// initialising an instance of postgres db
db := db.Init()
// using dependency injection to pass instance
// of db to contoller functions
h := controller.New(db)
router := router.CreateRoute(h)
// CORS
fmt.Println("Server is running on", host+":"+PORT)
router.Run(host + ":" + PORT)
// use ginSwagger middleware to serve the API docs
}