Skip to content
PiotrFerenc edited this page May 14, 2024 · 1 revision
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "net/http"
)

type Parameters struct {
    ConsoleText string `json:"consoleText"`
}

type TaskItem struct {
    Sequence int    `json:"sequence"`
    Name     string `json:"name"`
    Action   string `json:"action"`
}

type RequestPayload struct {
    Parameters Parameters `json:"parameters"`
    Tasks      []TaskItem `json:"tasks"`
}

func main() {
    url := "http://localhost:5000/execute"

    payload := RequestPayload{
        Parameters: Parameters{
            ConsoleText: "hallo word",
        },
        Tasks: []TaskItem{
            {
                Sequence: 1,
                Name:     "log",
                Action:   "console",
            },
        },
    }

    jsonContent, err := json.Marshal(payload)
    if err != nil {
        fmt.Println("Error marshaling JSON:", err)
        return
    }

    response, err := http.Post(url, "application/json", bytes.NewBuffer(jsonContent))
    if err != nil {
        fmt.Println("Error making POST request:", err)
        return
    }
    defer response.Body.Close()

    if response.StatusCode == http.StatusOK {
        var responseContent []byte
        response.Body.Read(responseContent)
        fmt.Println("Response:", string(responseContent))
    } else {
        fmt.Println("Error:", response.Status)
    }
}

Clone this wiki locally