-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
65 lines (52 loc) · 1.48 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
package main
import (
_ "backend/docs"
"backend/models"
"backend/routes"
"fmt"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
echoSwagger "github.com/swaggo/echo-swagger"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
// @title Swagger Product Service API
// @version 2.0
// @description This is a organisation service.
// @termsOfService http://swagger.io/terms/
// @contact.name API Support
// @contact.url http://www.swagger.io/support
// @contact.email support@swagger.io
// @license.name Apache 2.0
// @license.url http://www.apache.org/licenses/LICENSE-2.0.html
// @host localhost::8080
func main() {
db, err := gorm.Open(sqlite.Open("file::memory:?cache=shared"), &gorm.Config{})
if err != nil {
panic("failed to connect database")
}
err = db.AutoMigrate(&models.Product{}, &models.Vote{})
if err != nil {
panic("failed to migrate database")
}
db.Create(&models.Product{Name: "Product 1", Description: "Description 1"})
db.Create(&models.Product{Name: "Product 2", Description: "Description 2"})
db.Create(&models.Product{Name: "Product 3", Description: "Description 3"})
db.Create(&models.Product{Name: "Product 4", Description: "Description 4"})
var product models.Product
db.First(&product, 1)
fmt.Println(product)
e := echo.New()
e.Use(middleware.Logger())
e.Use(middleware.Recover())
e.GET(
"/swagger/*",
echoSwagger.WrapHandler,
)
routes.InitRouter(e, db)
// Start the server
err = e.Start(":8080")
if err != nil {
panic(err)
}
}