-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
83 lines (66 loc) · 1.65 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"net/http"
"github.com/gin-gonic/gin"
"github.com/go-playground/validator/v10"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
)
var db *gorm.DB
var validate *validator.Validate
// Helper method to set `db` to SQLite connection so we can make queries to `hackathons.db`
func ConnectDatabase() {
database, err := gorm.Open(sqlite.Open("hackathons.db"), &gorm.Config{})
if err != nil {
panic("Failed to connect to database!")
}
err = database.AutoMigrate(&Hackathon{}) // keeps our schema up to date
if err != nil {
return
}
db = database
}
// Defines what a `Hackathon` is
type Hackathon struct {
Id int `json:"id"`
Name string `json:"name"`
Date string `json:"date"`
Url string `json:"url"`
Location string `json:"location"`
}
// GET /hackathons
// Get all hackathons
func getHackathons(c *gin.Context) {
// Code goes here
}
// GET /hackathons/:id
// Get hackathon by ID
func getHackathonById(c *gin.Context) {
// Code goes here
}
// POST /hackathons
// Create a hackathon
func createHackathon(c *gin.Context) {
// Code goes here
}
// PATCH /hackathons/:id
// Update a hackathon
func updateHackathon(c *gin.Context) {
// Code goes here
}
// DELETE /hackathons/:id
// Delete a hackathon
func deleteHackathon(c *gin.Context) {
// Code goes here
}
func main() {
router := gin.Default()
validate = validator.New()
ConnectDatabase()
// router.GET("/hackathons", getHackathons)
// router.GET("/hackathons/:id", getHackathonById)
// router.POST("/hackathons", createHackathon)
// router.PATCH("/hackathons/:id", updateHackathon)
// router.DELETE("/hackathons/:id", deleteHackathon)
router.Run("localhost:8080")
}