package main
import (
"context"
"fmt"
"net"
"github.com/fastly/compute-sdk-go/fsthttp"
"github.com/fastly/compute-sdk-go/geo"
"github.com/fastly/compute-sdk-go/rtlog"
)
func main() {
fsthttp.ServeFunc(func(ctx context.Context, w fsthttp.ResponseWriter, r *fsthttp.Request) {
if r.URL.Path == "/log" {
client_geo, err := geo.Lookup(net.ParseIP(r.RemoteAddr))
if err != nil {
fmt.Print(err)
w.WriteHeader(fsthttp.StatusInternalServerError)
fmt.Fprint(w, "GEO Lookup Error: ", err)
return
}
query := r.URL.Query()
query.Add("clientCity", client_geo.City)
r.URL.RawQuery = query.Encode()
endpoint := rtlog.Open("s3_rum_data")
fmt.Fprintln(endpoint, r.URL.RawQuery)
w.WriteHeader(fsthttp.StatusNoContent)
return
}
w.WriteHeader(fsthttp.StatusNotFound)
})
}