#!/usr/bin/env bash set -euo pipefail mkdir -p internal/httpx internal/{fetch,health,proxy} cat > go.mod <<'EOF' module edge go 1.22 EOF cat > internal/httpx/client.go <<'EOF' package httpx import ( "context" "fmt" "time" ) // Options configures a request. It replaces the old positional timeout // argument; Do now takes a context and an Options value. type Options struct { Timeout time.Duration Retries int } // Do performs a request. // // Deprecated form, removed in this release: // // func Do(url string, timeout time.Duration) (string, error) func Do(ctx context.Context, url string, opts Options) (string, error) { if opts.Timeout <= 0 { return "", fmt.Errorf("httpx: timeout is required") } return "body of " + url, nil } EOF cat > internal/fetch/fetch.go <<'EOF' package fetch import ( "time" "edge/internal/httpx" ) func Page(url string) (string, error) { return httpx.Do(url, 5*time.Second) } EOF cat > internal/health/health.go <<'EOF' package health import ( "time" "edge/internal/httpx" ) func Check(url string) bool { _, err := httpx.Do(url, 2*time.Second) return err == nil } EOF cat > internal/proxy/proxy.go <<'EOF' package proxy import ( "time" "edge/internal/httpx" ) func Forward(url string) (string, error) { body, err := httpx.Do(url, 30*time.Second) if err != nil { return "", err } return body, nil } EOF git init -q . && git add -A && git -c user.email=e@x -c user.name=n commit -qm base