You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
613 B
Go

5 months ago
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
// Function to post data to an endpoint
func postData(data map[string]interface{}) error {
postURL := "http://localhost:8000/add_website" // Replace with your actual endpoint
jsonData, err := json.Marshal(data)
if err != nil {
return err
}
resp, err := http.Post(postURL, "application/json", bytes.NewBuffer(jsonData))
if err != nil {
return err
}
defer resp.Body.Close()
// Check response status if needed
if resp.StatusCode != http.StatusCreated {
return fmt.Errorf("unexpected status: %s", resp.Status)
}
return nil
}