-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
52 lines (40 loc) · 946 Bytes
/
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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
"github.com/shiftkey-labs/shiftkey-server/pkg/controller"
"github.com/shiftkey-labs/shiftkey-server/pkg/db"
)
func main() {
db.Connect()
// Run these two if you're running the server for the first time or have to migrate the db
// db.Migrate()
// db.Seed(db.DB)
router := gin.Default()
router.GET("/ping", func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, gin.H{
"message": "pong",
})
})
router.GET("/users", func(ctx *gin.Context) {
users, err := controller.GetAllUsers()
fmt.Print(users)
if err != nil {
ctx.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
ctx.JSON(http.StatusOK, users)
})
if err := godotenv.Load(); err != nil {
log.Fatal("Error loading .env file")
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
router.Run(":" + port)
}