Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
1f2810c765 |
9 changed files with 121 additions and 0 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -21,3 +21,5 @@
|
|||
# Go workspace file
|
||||
go.work
|
||||
|
||||
# build dir
|
||||
build/
|
5
Makefile
Normal file
5
Makefile
Normal file
|
@ -0,0 +1,5 @@
|
|||
client:
|
||||
go build -o build/client ./examples/client
|
||||
|
||||
server:
|
||||
go build -o build/server ./examples/server
|
14
config/config.go
Normal file
14
config/config.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package config
|
||||
|
||||
import "fmt"
|
||||
|
||||
type RMQConfig struct {
|
||||
Host string
|
||||
Port int
|
||||
User string
|
||||
Password string
|
||||
}
|
||||
|
||||
func (c *RMQConfig) URL() string {
|
||||
return fmt.Sprintf("amqp://%s:%s@%s:%d/", c.User, c.Password, c.Host, c.Port)
|
||||
}
|
15
event/event.go
Normal file
15
event/event.go
Normal file
|
@ -0,0 +1,15 @@
|
|||
package event
|
||||
|
||||
type Level int
|
||||
|
||||
const (
|
||||
LevelInfo Level = iota
|
||||
LevelWarning
|
||||
LevelError
|
||||
)
|
||||
|
||||
type Event struct {
|
||||
Level Level
|
||||
Message string
|
||||
Source string
|
||||
}
|
47
examples/client/client.go
Normal file
47
examples/client/client.go
Normal file
|
@ -0,0 +1,47 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.faercol.me/management-platform/events/config"
|
||||
amqp "github.com/rabbitmq/amqp091-go"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("coucou from client")
|
||||
|
||||
fmt.Println("connecting to RMQ")
|
||||
conf := config.RMQConfig{
|
||||
Host: "localhost",
|
||||
Port: 5672,
|
||||
User: "guest",
|
||||
Password: "guest",
|
||||
}
|
||||
|
||||
con, err := amqp.Dial(conf.URL())
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer con.Close()
|
||||
|
||||
ch, err := con.Channel()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
q, err := ch.QueueDeclare("example", false, false, false, false, nil)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
if err := ch.PublishWithContext(ctx, "", q.Name, false, false, amqp.Publishing{ContentType: "text/plain", Body: []byte("test message")}); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
fmt.Println("done")
|
||||
}
|
7
examples/server/server.go
Normal file
7
examples/server/server.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Coucou from server")
|
||||
}
|
5
go.mod
Normal file
5
go.mod
Normal file
|
@ -0,0 +1,5 @@
|
|||
module git.faercol.me/management-platform/events
|
||||
|
||||
go 1.22.0
|
||||
|
||||
require github.com/rabbitmq/amqp091-go v1.9.0 // indirect
|
17
go.sum
Normal file
17
go.sum
Normal file
|
@ -0,0 +1,17 @@
|
|||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rabbitmq/amqp091-go v1.9.0 h1:qrQtyzB4H8BQgEuJwhmVQqVHB9O4+MNDJCCAcpc3Aoo=
|
||||
github.com/rabbitmq/amqp091-go v1.9.0/go.mod h1:+jPrT9iY2eLjRaMSRHUhc3z14E/l85kv/f+6luSD3pc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
9
notifier/notifier.go
Normal file
9
notifier/notifier.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package notifier
|
||||
|
||||
import (
|
||||
"git.faercol.me/management-platform/events/event"
|
||||
)
|
||||
|
||||
type Notifier interface {
|
||||
Notify(event event.Event)
|
||||
}
|
Loading…
Reference in a new issue