From 451cdae78f57da88e873fa2d1695293e4f2385d3 Mon Sep 17 00:00:00 2001 From: Aarav Arora Date: Mon, 1 May 2023 17:36:09 +0530 Subject: [PATCH] feat: adding golang snippet for request --- README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/README.md b/README.md index aee2349..3f728a5 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,43 @@ print("Is spam:", result["is_spam"]) print("Spam probability:", result["spam_probability"]) ``` +### Go + +```go +package main + +import ( + "bytes" + "encoding/json" + "net/http" +) + +func main() { + url := "http://localhost:8000/spam_check" + data := map[string]string{"text": "subscribe to my youtube channel"} + jsonData, err := json.Marshal(data) + if err != nil { + panic(err) + } + + req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) + if err != nil { + panic(err) + } + + req.Header.Set("Content-Type", "application/json") + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + panic(err) + } + defer resp.Body.Close() + + // Do something with the response if needed +} +``` + ### Rust ```rust