Files
kontor/kontor-gin/internal/cmd/add-link.go
T
Thomas Peetz 094dffb1c7
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
add loading links form file
2026-10-07 18:50:09 +02:00

49 lines
1.1 KiB
Go

package cmd
import (
"encoding/json"
"log"
"log/slog"
"github.com/go-stomp/stomp/v3"
"github.com/spf13/cobra"
)
type Link struct {
Url string `json:"url"`
}
var addLinkCmd = &cobra.Command{
Use: "add-link",
Short: "Add Link",
Long: "Add Link to Kontor Database",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
slog.Info("add-link kontor started")
conn, err := stomp.Dial("tcp", "localhost:61616",
stomp.ConnOpt.Login("artemis", "artemis"), // Provide username and password
)
if err != nil {
log.Fatalf("failed to connect to Artemis: %s", err)
}
defer conn.Disconnect()
// sender := artemis.Sender{Addr: "localhost:61616", Dest: "add-link", Enc: artemis.EncodingJson}
link := &Link{Url: args[0]}
b, jsonErr := json.Marshal(link)
if jsonErr != nil {
slog.Info("Json encoding failed", "error", jsonErr.Error())
}
err = conn.Send("/queue/add-link", "application/json", b)
if err != nil {
slog.Info("send failed", "error", err.Error())
}
slog.Info("add-link kontor finished")
},
}
func init() {
rootCmd.AddCommand(addLinkCmd)
}