You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
809 B
40 lines
809 B
|
4 weeks ago
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"context"
|
||
|
|
"github.com/redis/go-redis/v9"
|
||
|
|
"encoding/json"
|
||
|
|
"fmt"
|
||
|
|
"MY/webapp/data"
|
||
|
|
)
|
||
|
|
|
||
|
|
func producer(ctx context.Context) {
|
||
|
|
client := redis.NewClient(&redis.Options{
|
||
|
|
Addr: "127.0.0.1:6379",
|
||
|
|
Password: "",
|
||
|
|
DB: 0,
|
||
|
|
})
|
||
|
|
|
||
|
|
_, err := client.Ping(ctx).Result()
|
||
|
|
if err != nil { panic(err) }
|
||
|
|
|
||
|
|
msg := data.EmailMessage{
|
||
|
|
To: "tina.recip@example.com",
|
||
|
|
From: "toni.sender@example.com",
|
||
|
|
Subject: "This is my first mail.",
|
||
|
|
Text: fmt.Sprintf("Random number %v", 200),
|
||
|
|
HTML: fmt.Sprintf("<h1>Random number %v</h1>", 200),
|
||
|
|
}
|
||
|
|
|
||
|
|
msg_json, err := json.Marshal(msg)
|
||
|
|
if err != nil { panic(err) }
|
||
|
|
|
||
|
|
_, err = client.LPush(ctx, "queue", string(msg_json)).Result()
|
||
|
|
if err != nil { panic(err) }
|
||
|
|
}
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
ctx := context.Background()
|
||
|
|
producer(ctx)
|
||
|
|
}
|