From 1f2810c765bf6546f008a76067fc9520feca0da9 Mon Sep 17 00:00:00 2001 From: Melora Hugues Date: Tue, 30 Apr 2024 18:39:50 +0200 Subject: [PATCH] backup --- .gitignore | 2 ++ Makefile | 5 +++++ config/config.go | 14 ++++++++++++ event/event.go | 15 +++++++++++++ examples/client/client.go | 47 +++++++++++++++++++++++++++++++++++++++ examples/server/server.go | 7 ++++++ go.mod | 5 +++++ go.sum | 17 ++++++++++++++ notifier/notifier.go | 9 ++++++++ 9 files changed, 121 insertions(+) create mode 100644 Makefile create mode 100644 config/config.go create mode 100644 event/event.go create mode 100644 examples/client/client.go create mode 100644 examples/server/server.go create mode 100644 go.mod create mode 100644 go.sum create mode 100644 notifier/notifier.go diff --git a/.gitignore b/.gitignore index adf8f72..0f28082 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,5 @@ # Go workspace file go.work +# build dir +build/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6135b87 --- /dev/null +++ b/Makefile @@ -0,0 +1,5 @@ +client: + go build -o build/client ./examples/client + +server: + go build -o build/server ./examples/server diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..3a22a5b --- /dev/null +++ b/config/config.go @@ -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) +} diff --git a/event/event.go b/event/event.go new file mode 100644 index 0000000..ff3729c --- /dev/null +++ b/event/event.go @@ -0,0 +1,15 @@ +package event + +type Level int + +const ( + LevelInfo Level = iota + LevelWarning + LevelError +) + +type Event struct { + Level Level + Message string + Source string +} diff --git a/examples/client/client.go b/examples/client/client.go new file mode 100644 index 0000000..87b0fef --- /dev/null +++ b/examples/client/client.go @@ -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") +} diff --git a/examples/server/server.go b/examples/server/server.go new file mode 100644 index 0000000..403bce2 --- /dev/null +++ b/examples/server/server.go @@ -0,0 +1,7 @@ +package main + +import "fmt" + +func main() { + fmt.Println("Coucou from server") +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..cfa6896 --- /dev/null +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..00c627d --- /dev/null +++ b/go.sum @@ -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= diff --git a/notifier/notifier.go b/notifier/notifier.go new file mode 100644 index 0000000..be663bc --- /dev/null +++ b/notifier/notifier.go @@ -0,0 +1,9 @@ +package notifier + +import ( + "git.faercol.me/management-platform/events/event" +) + +type Notifier interface { + Notify(event event.Event) +}