Skip to content

Instantly share code, notes, and snippets.

@pythoninthegrass
Last active May 14, 2025 02:38
Show Gist options
  • Save pythoninthegrass/73363599680380af824bf0b5acad7ee0 to your computer and use it in GitHub Desktop.
Save pythoninthegrass/73363599680380af824bf0b5acad7ee0 to your computer and use it in GitHub Desktop.
llm generated iris rest server to make gql requests
package main
import (
"context"
"fmt"
"net/http"
"strings"
"github.com/kataras/iris/v12"
"github.com/thepolyglotdeveloper/graphql"
)
func main() {
app := iris.New()
// Define a route for the GraphQL endpoint
app.Post("/graphql", handleGraphQLRequest)
// Start the server on port 8080
app.Run(iris.Addr(":8080"))
}
func handleGraphQLRequest(ctx iris.Context) {
query := ctx.FormValue("query")
variables := map[string]interface{}{}
// Execute the GraphQL query
result, err := graphql.ExecuteQuery(query, variables)
if err != nil {
ctx.JSON(iris.Map{"error": err.Error()})
return
}
// Post the results to Slack
slackWebhookURL := "YOUR_SLACK_WEBHOOK_URL"
postToSlack(slackWebhookURL, fmt.Sprintf("GraphQL Query Result: %v", result))
ctx.JSON(result)
}
func postToSlack(webhookURL string, message string) error {
reqBody := fmt.Sprintf(`{"text": "%s"}`, message)
resp, err := http.Post(webhookURL, "application/json", strings.NewReader(reqBody))
if err != nil {
return err
}
defer resp.Body.Close()
return nil
}
@pythoninthegrass
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment