package mainimport ("log""github.com/moonrhythm/parapet""github.com/moonrhythm/parapet/pkg/body""github.com/moonrhythm/parapet/pkg/compress""github.com/moonrhythm/parapet/pkg/headers""github.com/moonrhythm/parapet/pkg/healthz""github.com/moonrhythm/parapet/pkg/host""github.com/moonrhythm/parapet/pkg/hsts""github.com/moonrhythm/parapet/pkg/location""github.com/moonrhythm/parapet/pkg/logger""github.com/moonrhythm/parapet/pkg/ratelimit""github.com/moonrhythm/parapet/pkg/redirect""github.com/moonrhythm/parapet/pkg/requestid""github.com/moonrhythm/parapet/pkg/upstream")funcmain() {s:=parapet.New()s.Use(logger.Stdout())s.Use(requestid.New())s.Use(ratelimit.FixedWindowPerSecond(60))s.Use(ratelimit.FixedWindowPerMinute(300))s.Use(ratelimit.FixedWindowPerHour(2000))s.Use(body.LimitRequest(15*1024*1024))// 15 MiBs.Use(body.BufferRequest())s.Use(compress.Gzip())s.Use(compress.Br())// sitess.Use(example())s.Use(mysite())s.Use(wordpress())// health check{l:=location.Exact("/healthz")l.Use(logger.Disable())l.Use(healthz.New())s.Use(l)}s.Addr=":8080"err:=s.ListenAndServe()iferr!=nil {log.Fatal(err)}}funcexample() parapet.Middleware {h:=host.New("example.com","www.example.com")h.Use(ratelimit.FixedWindowPerSecond(20))h.Use(redirect.HTTPS())h.Use(hsts.Preload())h.Use(redirect.NonWWW())h.Use(upstream.New(upstream.NewRoundRobinLoadBalancer([]*upstream.Target{{Host:"example.default.svc.cluster.local:8080",Transport:&upstream.HTTPTransport{}},{Host:"example1.default.svc.cluster.local:8080",Transport:&upstream.H2CTransport{}},{Host:"myexamplebackuphost.com",Transport:&upstream.HTTPSTransport{}},})))returnh}funcmysite() parapet.Middleware {varhs parapet.Middlewares{h:=host.New("mysiteaaa.io","www.mysiteaaa.io")h.Use(ratelimit.FixedWindowPerSecond(15))h.Use(redirect.HTTPS())h.Use(hsts.Preload())h.Use(redirect.WWW())h.Use(headers.DeleteResponse("Server","x-goog-generation","x-goog-hash","x-goog-meta-goog-reserved-file-mtime","x-goog-metageneration","x-goog-storage-class","x-goog-stored-content-encoding","x-goog-stored-content-length","x-guploader-uploadid",))h.Use(upstream.SingleHost("storage.googleapis.com",&upstream.HTTPSTransport{}))hs.Use(h)}{h:=host.New("mail.mysiteaaa.io")h.Use(redirect.HTTPS())h.Use(hsts.Preload())h.Use(redirect.To("https://mail.google.com/a/mysiteaaa.io",302))hs.Use(h)}returnhs}funcwordpress() parapet.Middleware {h:=host.New("myblogaaa.com","www.myblogaaa.com")h.Use(ratelimit.FixedWindowPerMinute(150))h.Use(redirect.HTTPS())h.Use(hsts.Preload())h.Use(redirect.NonWWW())backend:=upstream.SingleHost("wordpress.default.svc.cluster.local",&upstream.HTTPTransport{})l:=location.RegExp(`\.(js|css|svg|png|jp(e)?g|gif)$`)l.Use(headers.SetResponse("Cache-Control","public, max-age=31536000"))l.Use(backend)h.Use(l)h.Use(backend)returnh}