-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (37 loc) · 1.01 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
package main
import (
"go-api-producer/adapters"
"go-api-producer/config"
"log"
"net/http"
"os"
"time"
"github.com/labstack/echo"
)
func main() {
c := config.Init(os.Getenv("APP_ENV"))
e := echo.New()
e.GET("/ping", func(c echo.Context) error {
return c.String(http.StatusOK, "pong")
})
e.GET("/send", func(c echo.Context) error {
fruit := &Fruit{Name: "apple"}
adapters.MessagePublisher.Publish(c.Request().Context(), fruit, adapters.EventCreatedFruit)
return c.String(http.StatusOK, "sended")
})
adapters.NewMessagePublisher(c.EventBroker.Kafka)
defer adapters.MessagePublisher.Close()
if err := e.Start(":8090"); err != nil {
log.Println(err)
}
}
type Fruit struct {
Id int64 `json:"id"`
Code string `json:"code"`
Name string `json:"name"`
Color string `json:"color"`
Price int64 `json:"price"`
StoreCode string `json:"storeCode"`
CreatedAt time.Time `json:"createdAt" xorm:"created"`
UpdatedAt time.Time `json:"updatedAt" xorm:"updated"`
}