-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
51 lines (41 loc) · 1.25 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 (
"GoProject/database"
"GoProject/external"
"GoProject/routes"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"log"
)
func welcome(c *fiber.Ctx) error {
return c.SendString("Welcome to my API")
}
func setupRoutes(app *fiber.App) {
// Welcome
app.Get("/api", welcome)
//User
app.Post("/api/users", routes.CreateUser)
app.Get("/api/users", routes.GetUsers)
app.Get("api/users/:id", routes.GetUser)
app.Put("api/users/:id", routes.UpdateUser)
app.Delete("/api/users/:id", routes.DeleteUser)
//Favourite
app.Post("/api/favourite", routes.CreateFavourite)
app.Get("/api/favourite/", routes.GetFavourites)
//Finhub Integration
app.Get("/api/stocks/price/:name", external.GetCurrentStockPrice)
app.Get("/api/stocks/forecast/:name", external.BuyOrSell)
}
//Need to implment company routes left : video-> 51:24
func main() {
database.ConnectDb()
app := fiber.New()
app.Use(cors.New(cors.Config{
AllowHeaders: "Origin,Content-Type,Accept,Content-Length,Accept-Language,Accept-Encoding,Connection,Access-Control-Allow-Origin",
AllowOrigins: "*",
AllowCredentials: true,
AllowMethods: "GET,POST,HEAD,PUT,DELETE,PATCH,OPTIONS",
}))
setupRoutes(app)
log.Fatal(app.Listen(":3000"))
}