package cmd import ( "encoding/json" "fmt" "kontor-api-gin/internal/helpers" "log/slog" "os" "github.com/go-stomp/stomp/v3" "github.com/spf13/cobra" ) var addLinksCmd = &cobra.Command{ Use: "add-links [file]", Short: "Add Links", Long: "Add Links", Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { conn, err := stomp.Dial("tcp", "localhost:61616", stomp.ConnOpt.Login("artemis", "artemis"), // Provide username and password ) if err != nil { slog.Info("failed to connect to Artemis: %s", err) os.Exit(1) } defer conn.Disconnect() fileName := args[0] slog.Info(fmt.Sprintf("add Links from %s", fileName)) lines, err := helpers.LinesInFile(fileName) if err != nil { slog.Warn("add links failed", "error", err) os.Exit(1) } for _, line := range lines { b, jsonErr := json.Marshal(line) if jsonErr != nil { slog.Info("Json encoding failed", "error", jsonErr.Error()) } err = conn.Send("media.link", "application/json", b) if err != nil { slog.Info("send failed", "error", err.Error()) } } }, } func init() { rootCmd.AddCommand(addLinksCmd) }