-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
36 lines (31 loc) · 801 Bytes
/
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
package main
import (
"fmt"
"github.com/behzadsp/go-fiber-crm/database"
"github.com/behzadsp/go-fiber-crm/lead"
"github.com/gofiber/fiber"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
func setupRoutes(app *fiber.App) {
app.Get("/api/v1/lead", lead.GetLeads)
app.Get("/api/v1/lead/:id", lead.GetLead)
app.Post("/api/v1/lead", lead.NewLead)
app.Delete("/api/v1/lead/:id", lead.DeleteLead)
}
func initDatabase() {
var err error
database.DBConn, err = gorm.Open(sqlite.Open("leads.db"), &gorm.Config{})
if err != nil {
panic("Failed to open DB connection!")
}
fmt.Println("Successfully opened connection to database.")
database.DBConn.AutoMigrate(&lead.Lead{})
fmt.Println("Database migrated.")
}
func main() {
app := fiber.New()
initDatabase()
setupRoutes(app)
app.Listen(3000)
}