-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
56 lines (43 loc) · 813 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"log"
"net/http"
"os"
"github.com/urfave/cli/v2"
"github.com/gin-gonic/gin"
)
type Event struct {
Name string `json:"name"`
}
func HandleEvents(c *gin.Context) {
var newEvent Event
// Call BindJSON to bind the received JSON to
// newAlbum.
if err := c.BindJSON(&newEvent); err != nil {
return
}
c.IndentedJSON(http.StatusOK, newEvent)
}
func main() {
app := &cli.App{
Commands: []*cli.Command{
{
Name: "serve",
Aliases: []string{"s"},
Usage: "Runs the server",
Action: func(cCtx *cli.Context) error {
EventServer()
return nil
},
},
},
}
if err := app.Run(os.Args); err != nil {
log.Fatal(err)
}
}
func EventServer() {
router := gin.Default()
router.POST("/events", HandleEvents)
router.Run("localhost:8080")
}