🎉 Bem-vindo! Sinfonia é uma plataforma completa de orquestração de robôs, solicite já seu acesso.
Binary (exe/elf)

Binary (exe/elf)

This section describes how to prepare and deploy an executable written in GO in the orchestrator. For the publication to be successful, the following files must be present:

Warning

The main.exe file generated after the build process must be compressed for publication.

Script Example

Folder setup

mkdir go-api-request
cd go-api-request

Initialize module

go mod init go-api-request

Example code

Now let’s create a simple automation that makes API requests.

// main.go
package main

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

type Post struct {
	UserID int    `json:"userId"`
	ID     int    `json:"id"`
	Title  string `json:"title"`
	Body   string `json:"body"`
}

func main() {
	// API URL
	url := "https://jsonplaceholder.typicode.com/posts"

	// Make GET request to the API
	resp, err := http.Get(url)
	if err != nil {
		log.Fatalf("Error making request: %v", err)
	}
	defer resp.Body.Close()

	// Check response status
	if resp.StatusCode != http.StatusOK {
		log.Fatalf("Error: Status code %d", resp.StatusCode)
	}

	// Decode JSON response
	var posts []Post
	if err := json.NewDecoder(resp.Body).Decode(&posts); err != nil {
		log.Fatalf("Error decoding JSON response: %v", err)
	}

	// Display data in terminal
	fmt.Println("Posts received from API:")
	for _, post := range posts {
		fmt.Printf("ID: %d\n", post.ID)
		fmt.Printf("Title: %s\n", post.Title)
		fmt.Printf("Body: %s\n", post.Body)
		fmt.Println("--------------")
	}
}

Running the script

# update dependencies
go mod tidy
# run script
go run main.go

Building the executable

Now it’s necessary to compile the project according to the desired architecture to deploy the executable.

Note

Use WSL/Linux to run build commands.

Windows

GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -ldflags="-s -w" -o main.exe main.go

Linux

@GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o main cmd/*.go

Publication

Follow the instructions in the Publish Bot section to publish your project in .zip format.

Last updated on