Skip to content

Instantly share code, notes, and snippets.

@danielestevez
Created June 29, 2023 14:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danielestevez/5c366e4e8fba3a73ebcea303b738e4b9 to your computer and use it in GitHub Desktop.
Save danielestevez/5c366e4e8fba3a73ebcea303b738e4b9 to your computer and use it in GitHub Desktop.
Send notification to slack webhook
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
)
func main() {
webhookURL := "https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
message := map[string]string{
"text": "Hello, Slack!",
}
jsonMessage, err := json.Marshal(message)
if err != nil {
fmt.Println("Failed to marshal JSON:", err)
return
}
response, err := http.Post(webhookURL, "application/json", bytes.NewBuffer(jsonMessage))
if err != nil {
fmt.Println("Failed to send message to Slack:", err)
return
}
defer response.Body.Close()
fmt.Println("Notification sent successfully!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment