-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
51 lines (41 loc) · 1.06 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
package main
import (
"database/sql"
"fmt"
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
_ "github.com/lib/pq"
"log"
"main/src/config"
"main/src/middleware"
"os"
)
func main() {
var err error
port := os.Getenv("PORT")
if port == "" {
log.Fatal("$PORT must be set")
}
fmt.Println("Hello")
//connect to DB
config.DB, err = sql.Open("postgres", os.Getenv("DATABASE_URL"))
if err != nil {
panic(err)
}
//defer db.Close()
fmt.Println("successfully connected")
r := gin.Default()
r.Use(cors.Default())
r.GET("/acc", middleware.GetAllAccounts)
r.GET("/acc/:id", middleware.GetAccountbyId)
r.POST("/entry", middleware.Addaccount)
r.GET("/task", middleware.GetAllTask)
r.GET("/task/:id", middleware.GetTaskbyId)
r.POST("/task/entry", middleware.Addtask)
r.DELETE("/task/delete/:id", middleware.DeleteTask)
r.PATCH("/task/entry/:id", middleware.UpdateTaskbyid)
r.GET("/categories", middleware.GetAllCategories)
r.POST("/categories/entry", middleware.AddCat)
r.DELETE("/categories/delete/:name", middleware.DeleteCat)
r.Run(":" + port)
}