• Programming

    Small Go Script To Send Some JSON To An Endpoint

    The following was written to act as a Google Cloud Function or Lambda, and sends a simple POST to a standard rest endpoint at https://krypted.com/api/v1/sites with the json defined in jsonObject. The endpoint can easily be changed in http.NewRequest or converted to a variable. The response to the POST is then returned as stdout. package main import ( "fmt" "net/http" "encoding/json" ) func main() { // Create a new HTTP client. client := &http.Client{} // Create a new JSON object. jsonObject := map[string]string{ "name": "Krypted", "site": "www.krypted.com", } // Marshal the JSON object to a string. jsonString, err := json.Marshal(jsonObject) if err != nil { fmt.Println(err) return } // Create…