-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
44 lines (38 loc) · 1.71 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
package main
import (
"fmt"
"log"
"github.com/audstanley/coffeeorders-go/handlers"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
)
func main() {
handlers.CreateDb()
config := fiber.Config{
DisableStartupMessage: true,
}
app := fiber.New(config)
app.Use(cors.New(cors.Config{
AllowOrigins: "*",
AllowHeaders: "content-type",
ExposeHeaders: "*",
}))
fmt.Println("Source code for this API can be found at: https://www.github.com/audstanley/coffeeorders-go")
fmt.Println(" Written in GoLang using the Fiber library")
fmt.Println(" Feel free to add a star on GitHub 😊")
fmt.Println(" You will need this VSCode Extension: https://marketplace.visualstudio.com/items?itemName=humao.rest-client")
fmt.Println(" And you will want to use the files in this folder to test the endpoints:")
fmt.Println(" https://github.com/audstanley/coffeeorders-go/tree/main/rest\n")
fmt.Println(" Written By: Richard Stanley")
fmt.Println(" For: Professor William McCarthy @ CSUF\n")
fmt.Println("==========================================")
fmt.Println("CoffeeOrders API running on\n\thttp://localhost:3001/coffeeorders\n==========================================\n")
app.Get("/", handlers.Root)
app.Get("/coffeeorders", handlers.ListCoffeeOrders)
app.Post("/coffeeorders", handlers.PostACoffeeOrder)
app.Get("/coffeeorders/:emailAddress", handlers.ListCoffeeOrdersByEmailAddress)
app.Delete("/coffeeorders", handlers.DeleteAllCoffeeOrders)
app.Delete("/coffeeorders/:emailAddress", handlers.DeleteSingleNewestCoffeeOrderByEmailAddress)
app.Put("/coffeeorders/:emailAddress", handlers.PutCoffeeOrderOverExistingByEmail)
log.Fatal(app.Listen(fmt.Sprintf(":%s", "3001")))
}