-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
96 lines (76 loc) · 1.87 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
93
94
95
96
package main
import (
"fmt"
"os"
"github.com/go-playground/validator/v10"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
jwtware "github.com/gofiber/jwt/v3"
"gorm.io/gorm"
)
var (
config = Config{
dsn: os.Getenv("DATABASE_URL") + "?sslmode=require",
}
db = func() *gorm.DB {
db, err := connect(config)
if err != nil {
panic(err)
}
if err := migrateAll(db); err != nil {
panic(err)
}
return db
}()
app = fiber.New()
validate = validator.New()
)
func init() {
// if port := os.Getenv("PORT"); port != "" {
// app.Listen(":" + port)
// } else {
// app.Listen(":8080")
// }
}
func main() {
app.Use(cors.New())
fmt.Println(fmt.Sprintln("Connected to", "server", "as", "hamid"))
app.Get("/", getDefault)
sessions := app.Group("/auth")
sessions.Post("/signup", signUpUser)
sessions.Post("/login", loginUser)
user := app.Group("/user")
user.Use(jwtware.New(jwtware.Config{
SigningKey: []byte("bananas"),
}))
user.Get("/", getUser)
user.Put("/", updateUser)
user.Delete("/", deleteUser)
notebooks := app.Group("/notebooks")
notebooks.Use(jwtware.New(jwtware.Config{
SigningKey: []byte("bananas"),
}))
notebooks.Get("/", getNotebook)
notebooks.Get("/all", getAllNotebooks)
notebooks.Post("/", createNotebook)
notebooks.Put("/", updateNotebook)
notebooks.Delete("/", deleteNotebook)
notes := app.Group("/notes")
notes.Use(jwtware.New(jwtware.Config{
SigningKey: []byte("bananas"),
}))
notes.Post("/", getNote)
notes.Get("/all", getAllNotes)
notes.Post("/create", createNote)
notes.Put("/", updateNote)
notes.Delete("/", deleteNote)
public := app.Group("/public")
public.Get("/", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{
"success": true,
"path": "public"})
})
if err := app.Listen(":" + os.Getenv("PORT")); err != nil {
panic(err)
}
}