-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
57 lines (48 loc) · 1.37 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/joho/godotenv"
"github.com/labstack/echo/v4"
"github.com/pranotobudi/go-simple-ecommerce/api/products"
"github.com/pranotobudi/go-simple-ecommerce/api/users"
)
func main() {
if os.Getenv("APP_ENV") != "production" {
// executed in development only,
//for production set those on production environment settings
// load local env variables to os
err := godotenv.Load(".env")
if err != nil {
log.Println("failed to load .env file")
}
}
// Product
// db := database.GetDBInstance()
pr := products.NewProductRepository()
pr.FreshProductMigrator()
pr.ProductDataSeed()
productsList, _ := pr.GetProducts()
fmt.Println(productsList)
//User
ur := users.NewUserRepository()
ur.FreshUserMigrator()
ur.UserDataSeed()
user, _ := ur.GetUserByEmail("emailusername1@gmail.com")
fmt.Println(user)
productHandler := products.NewProductHandler()
userHandler := users.NewUserHandler()
e := echo.New()
e.GET("/", hello)
e.POST("/api/v1/search", productHandler.SearchProducts)
e.GET("/api/v1/products", productHandler.GetProducts)
e.POST("/api/v1/register", userHandler.RegisterUser)
e.POST("/api/v1/login", userHandler.UserLogin)
e.Static("/static", "assets")
e.Logger.Fatal(e.Start(":" + os.Getenv("PORT")))
}
func hello(c echo.Context) error {
return c.String(http.StatusOK, "Hello, Go World!")
}