package main import ( "encoding/json" "net/http" "net/url" "os" ) type CaptchaResponse struct { Success bool `json:"success"` } func ValidateCaptcha(captcha string) bool { secretKey := os.Getenv("CAPTCHA_SERVER_KEY") if secretKey == "" { return true // Skip validation if CAPTCHA is disabled } resp, err := http.PostForm("https://www.google.com/recaptcha/api/siteverify", url.Values{ "secret": {secretKey}, "response": {captcha}, }) if err != nil { return false } defer resp.Body.Close() var result CaptchaResponse err = json.NewDecoder(resp.Body).Decode(&result) return err == nil && result.Success }