Chapter 5.6 • Backend Runtimes
Go (Golang & Gin) Backend Integration
High-throughput, sub-millisecond Go middleware and client libraries for microservices and API gateways.
Go Standard Library / Gin Middleware
Perform non-blocking HTTP requests to the Cloudflare Edge KV namespace:
package main
import (
"encoding/json"
"fmt"
"net/http"
"time"
)
type ParityResult struct {
Eligible bool `json:"eligible"`
CountryCode string `json:"countryCode"`
CountryName string `json:"countryName"`
DiscountPercentage int `json:"discountPercentage"`
CouponCode string `json:"couponCode"`
}
var httpClient = &http.Client{
Timeout: 2 * time.Second,
}
func ResolveParity(projectID, clientIP string) (*ParityResult, error) {
url := fmt.Sprintf("https://parityedge-edge-api.g-saichakri.workers.dev/v1/resolve?projectId=%s", projectID)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("CF-Connecting-IP", clientIP)
resp, err := httpClient.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
var result ParityResult
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
return nil, err
}
return &result, nil
}Next: PHP & Laravel Guide
Integrate ParityEdge into Laravel, WooCommerce, and WordPress storefronts.