| 7 | ) |
| 8 | |
| 9 | func main() { |
| 10 | app := iris.New() |
| 11 | |
| 12 | app.Get("/", func(ctx iris.Context) { |
| 13 | ctx.Writef("Hello from the server") |
| 14 | }) |
| 15 | |
| 16 | app.Get("/mypath", func(ctx iris.Context) { |
| 17 | ctx.Writef("Hello from %s", ctx.Path()) |
| 18 | }) |
| 19 | |
| 20 | // call .Build before use the 'app' as a http.Handler on a custom http.Server |
| 21 | app.Build() |
| 22 | |
| 23 | // create our custom server and assign the Handler/Router |
| 24 | srv := &http.Server{Handler: app, Addr: ":8080"} // you have to set Handler:app and Addr, see "iris-way" which does this automatically. |
| 25 | // http://localhost:8080/ |
| 26 | // http://localhost:8080/mypath |
| 27 | println("Start a server listening on http://localhost:8080") |
| 28 | srv.ListenAndServe() // same as app.Listen(":8080") |
| 29 | |
| 30 | // Notes: |
| 31 | // Banner is not shown at all. Same for the Interrupt Handler, even if app's configuration allows them. |
| 32 | // |
| 33 | // `.Run` is the only one function that cares about those three. |
| 34 | |
| 35 | // More: |
| 36 | // see "multi" if you need to use more than one server at the same app. |
| 37 | // |
| 38 | // for a custom listener use: iris.Listener(net.Listener) or |
| 39 | // iris.TLS(cert,key) or iris.AutoTLS(), see "custom-listener" example for those. |
| 40 | } |