package main
import (
"context"
"fmt"
"io"
"regexp"
"github.com/fastly/compute-sdk-go/fsthttp"
)
const BackendName = "origin_0"
func main() {
fsthttp.ServeFunc(func(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Request) {
re := regexp.MustCompile(`^/status/(\d+)`)
match := re.FindStringSubmatch(r.URL.Path)
fmt.Println(match[1])
re = regexp.MustCompile(`^/(?:status|code)/(\d+)`)
match = re.FindStringSubmatch(r.URL.Path)
fmt.Println(match[1])
re = regexp.MustCompile(`&?aaa=([^&]*)`)
match = re.FindStringSubmatch(r.URL.RawQuery)
fmt.Println(match[1])
re = regexp.MustCompile(`&?a{2,6}=(foo|bar)(?:$|&)`)
match = re.FindStringSubmatch(r.URL.RawQuery)
fmt.Println(match[1])
re = regexp.MustCompile(`(?i)AaA=Foo`)
match = re.FindStringSubmatch(r.URL.RawQuery)
fmt.Println(match[0])
resp, err := r.Send(ctx, BackendName)
if err != nil {
w.WriteHeader(fsthttp.StatusBadGateway)
fmt.Fprintln(w, err.Error())
return
}
w.Header().Reset(resp.Header)
w.WriteHeader(resp.StatusCode)
io.Copy(w, resp.Body)
})
}