Skip to content

Instantly share code, notes, and snippets.

@ionutvilie
Created April 18, 2018 20:21
Show Gist options
  • Save ionutvilie/2d0b83fba5c6a1268c4284cebe673a3e to your computer and use it in GitHub Desktop.
Save ionutvilie/2d0b83fba5c6a1268c4284cebe673a3e to your computer and use it in GitHub Desktop.
$ go run main.go
Now listening on: http://localhost:9090
Application started. Press CMD+C to shut down.
[INFO] 2018/04/18 23:17 /authorize?fooo=bar&bar=foo
[INFO] 2018/04/18 23:17 200 732.308µs ::1 GET /authorize
[INFO] 2018/04/18 23:17 /authorize?fooo=bar&bar=foo
[INFO] 2018/04/18 23:17 200 51.315µs ::1 GET /authorize
[ERRO] 2018/04/18 23:17 /authorize/sre?fooo=bar&bar=foo
[ERRO] 2018/04/18 23:17 /authorize/sre?fooo=bar&bar=foo
package main
import (
"github.com/iris-contrib/middleware/cors"
"github.com/kataras/iris"
"github.com/kataras/iris/middleware/logger"
)
func newApp() *iris.Application {
app := iris.New()
// app.Use(recover.New())
app.Use(logger.New())
crs := cors.New(cors.Options{
AllowedOrigins: []string{"*"}, // allows everything, use that to change the hosts.
AllowCredentials: true,
})
app.OnErrorCode(iris.StatusNotFound, func(ctx iris.Context) {
ctx.WriteString(ctx.Path() + "?" + ctx.Request().URL.RawQuery)
app.Logger().Error(ctx.Path() + "?" + ctx.Request().URL.RawQuery)
})
app.Get("/authorize", func(ctx iris.Context) {
app.Logger().Info(ctx.Path() + "?" + ctx.Request().URL.RawQuery)
ctx.WriteString(ctx.Path() + "?" + ctx.Request().URL.RawQuery)
// ctx.WriteString(fmt.Sprintf("%v", ctx.Request().URL.Path()))
})
authorize := app.Party("/authorize")
authorize.Use(crs)
{
authorize.Get("/home", func(ctx iris.Context) {
result2 := `[{ "label": "foo", "href": "bar" }, { "label": "bar", "href": "foo" }]`
ctx.ContentType("application/json")
ctx.WriteString(result2)
})
authorize.Get("/about", func(ctx iris.Context) {
ctx.WriteString("Hello from /about")
})
authorize.Post("/send", func(ctx iris.Context) {
ctx.WriteString("sent")
})
}
return app
}
func main() {
app := newApp()
app.Run(iris.Addr(":9090"))
}
INFO[2018-04-18T23:17:37+03:00] Skipping same configuration for provider file
DEBU[2018-04-18T23:17:38+03:00] Creating frontend frontend1
DEBU[2018-04-18T23:17:38+03:00] Wiring frontend frontend1 to entryPoint http
DEBU[2018-04-18T23:17:38+03:00] Creating route authorize Path:/authorize, /authorize/{realm:[a-z]+};ReplacePathRegex:^/authorize/([a-zA-Z].+)+(\?.+) /authorize$2&realm_id=$1
DEBU[2018-04-18T23:17:38+03:00] Creating backend backend1
DEBU[2018-04-18T23:17:38+03:00] Creating load-balancer wrr
DEBU[2018-04-18T23:17:38+03:00] Creating server server1 at http://localhost:9090 with weight 2
DEBU[2018-04-18T23:17:38+03:00] Creating server server0 at http://localhost:9090 with weight 1
INFO[2018-04-18T23:17:38+03:00] Server configuration reloaded on :8081
INFO[2018-04-18T23:17:38+03:00] Server configuration reloaded on :8080
DEBU[2018-04-18T23:17:47+03:00] vulcand/oxy/roundrobin/rr: begin ServeHttp on request Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/authorize/sre\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"fooo=bar\\u0026bar=foo\",\"Fragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Content-Type\":[\"application/json\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:8081\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"127.0.0.1:52725\",\"RequestURI\":\"/authorize/sre?fooo=bar\\u0026bar=foo\",\"TLS\":null}"
DEBU[2018-04-18T23:17:47+03:00] vulcand/oxy/roundrobin/rr: Forwarding this request to URL Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/authorize/sre\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"fooo=bar\\u0026bar=foo\",\"Fragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Content-Type\":[\"application/json\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:8081\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"127.0.0.1:52725\",\"RequestURI\":\"/authorize/sre?fooo=bar\\u0026bar=foo\",\"TLS\":null}" ForwardURL="http://localhost:9090"
DEBU[2018-04-18T23:17:47+03:00] vulcand/oxy/forward: begin ServeHttp on request Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"localhost:9090\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Content-Type\":[\"application/json\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:8081\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"127.0.0.1:52725\",\"RequestURI\":\"/authorize/sre?fooo=bar\\u0026bar=foo\",\"TLS\":null}"
DEBU[2018-04-18T23:17:47+03:00] vulcand/oxy/forward/http: begin ServeHttp on request Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"localhost:9090\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Content-Type\":[\"application/json\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:8081\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"127.0.0.1:52725\",\"RequestURI\":\"/authorize/sre?fooo=bar\\u0026bar=foo\",\"TLS\":null}"
DEBU[2018-04-18T23:17:47+03:00] vulcand/oxy/forward/http: Round trip: http://localhost:9090, code: 404, Length: 31, duration: 404.4µs
DEBU[2018-04-18T23:17:47+03:00] vulcand/oxy/forward/http: completed ServeHttp on request Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"localhost:9090\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Content-Type\":[\"application/json\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:8081\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"127.0.0.1:52725\",\"RequestURI\":\"/authorize/sre?fooo=bar\\u0026bar=foo\",\"TLS\":null}"
DEBU[2018-04-18T23:17:47+03:00] vulcand/oxy/forward: completed ServeHttp on request Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"http\",\"Opaque\":\"\",\"User\":null,\"Host\":\"localhost:9090\",\"Path\":\"\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"\",\"Fragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Content-Type\":[\"application/json\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:8081\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"127.0.0.1:52725\",\"RequestURI\":\"/authorize/sre?fooo=bar\\u0026bar=foo\",\"TLS\":null}"
DEBU[2018-04-18T23:17:47+03:00] vulcand/oxy/roundrobin/rr: competed ServeHttp on request Request="{\"Method\":\"GET\",\"URL\":{\"Scheme\":\"\",\"Opaque\":\"\",\"User\":null,\"Host\":\"\",\"Path\":\"/authorize/sre\",\"RawPath\":\"\",\"ForceQuery\":false,\"RawQuery\":\"fooo=bar\\u0026bar=foo\",\"Fragment\":\"\"},\"Proto\":\"HTTP/1.1\",\"ProtoMajor\":1,\"ProtoMinor\":1,\"Header\":{\"Content-Type\":[\"application/json\"]},\"ContentLength\":0,\"TransferEncoding\":null,\"Host\":\"localhost:8081\",\"Form\":null,\"PostForm\":null,\"MultipartForm\":null,\"Trailer\":null,\"RemoteAddr\":\"127.0.0.1:52725\",\"RequestURI\":\"/authorize/sre?fooo=bar\\u0026bar=foo\",\"TLS\":null}"
defaultEntryPoints = ["http"]
# Log level
logLevel = "DEBUG"
[web]
address = ":8080"
[entryPoints]
[entryPoints.http]
address = ":8081"
[file]
[backends]
[backends.backend1]
[backends.backend1.servers]
[backends.backend1.servers.server0]
url = "http://localhost:9090"
weight = 1
[backends.backend1.servers.server1]
url = "http://localhost:9090"
weight = 2
[frontends]
[frontends.frontend1]
entryPoints = ["http"]
backend = "backend1"
passHostHeader = true
[frontends.frontend1.routes]
# [frontends.frontend1.routes.authorize]
# rule = "Path:/authorize"
[frontends.frontend1.routes.authorize]
rule = "Path:/authorize, /authorize/{realm:[a-z]+};ReplacePathRegex:^/authorize/([a-zA-Z].+)+(\\?.+) /authorize$2&realm_id=$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment