github.com/gramework/gramework@v1.8.1-0.20231027140105-82555c9057f5/test/behind_test/main.go (about) 1 package main 2 3 import ( 4 "os" 5 6 "github.com/gramework/gramework" 7 "github.com/gramework/gramework/behind/akamai" 8 ) 9 10 func main() { 11 app := gramework.New() 12 13 csv, err := os.ReadFile("./testdata/all-cidr-blocks.csv") 14 must(err) 15 akamCIDR, err := akamai.ParseCIDRBlocksCSV(csv, true, true) 16 must(err) 17 app.Behind(akamai.New(akamai.CIDRBlocks(akamCIDR))) 18 19 app.GET("/", func(ctx *gramework.Context) { 20 ctx.WriteString(ctx.RemoteIP().String()) 21 }) 22 23 app.ListenAndServe() 24 } 25 26 func must(err error) { 27 if err != nil { 28 panic(err) 29 } 30 }