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
|
package main
import (
"fmt"
"log"
"net/http"
"os"
"github.com/Baitinq/fs-tracer-backend/src/rest-api/handler"
amqp "github.com/rabbitmq/amqp091-go"
)
func main() {
rabbitmq_password, ok := os.LookupEnv("RABBITMQ_PASSWORD")
if !ok {
panic("RABBITMQ_PASSWORD not set")
}
log.Println("RabbitMQ password", rabbitmq_password)
conn, err := amqp.Dial(fmt.Sprintf("amqp://user:%s@rabbitmq:5672/", rabbitmq_password))
if err != nil {
panic(err)
}
defer conn.Close()
ch, err := conn.Channel()
if err != nil {
panic(err)
}
defer ch.Close()
q, err := ch.QueueDeclare(
"hello", // name
false, // durable
false, // delete when unused
false, // exclusive
false, // no-wait
nil, // arguments
)
if err != nil {
panic(err)
}
handler := handler.NewHandler(ch, q.Name)
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "Hello folks!")
})
mux.Handle("/payload", handler)
http.ListenAndServe(":8080", mux)
}
|