package main
import (
"context"
"fmt"
"io"
"github.com/fastly/compute-sdk-go/fsthttp"
"github.com/fastly/compute-sdk-go/rtlog"
)
func main() {
fsthttp.ServeFunc(func(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Request) {
endpoint := rtlog.Open("my_endpoint_name")
fmt.Fprintln(endpoint, r.URL.Path+" "+r.RemoteAddr)
resp, err := r.Send(ctx, "origin_0")
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)
})
}