| 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 | // Note: It's not needed if the first action is "go app.Run". |
| 21 | if err := app.Build(); err != nil { |
| 22 | panic(err) |
| 23 | } |
| 24 | |
| 25 | // start a secondary server listening on localhost:9090. |
| 26 | // use "go" keyword for Listen functions if you need to use more than one server at the same app. |
| 27 | // |
| 28 | // http://localhost:9090/ |
| 29 | // http://localhost:9090/mypath |
| 30 | srv1 := &http.Server{Addr: ":9090", Handler: app} |
| 31 | go srv1.ListenAndServe() |
| 32 | println("Start a server listening on http://localhost:9090") |
| 33 | |
| 34 | // start a "second-secondary" server listening on localhost:5050. |
| 35 | // |
| 36 | // http://localhost:5050/ |
| 37 | // http://localhost:5050/mypath |
| 38 | srv2 := &http.Server{Addr: ":5050", Handler: app} |
| 39 | go srv2.ListenAndServe() |
| 40 | println("Start a server listening on http://localhost:5050") |
| 41 | |
| 42 | // Note: app.Run is totally optional, we have already built the app with app.Build, |
| 43 | // you can just make a new http.Server instead. |
| 44 | // http://localhost:8080/ |
| 45 | // http://localhost:8080/mypath |
| 46 | app.Listen(":8080") // Block here. |
| 47 | } |