mirror of
https://github.com/kataras/iris.git
synced 2025-01-24 11:11:03 +01:00
7a6cf4c5aa
Part 3. Former-commit-id: 229b86baca4043c69517968318d9a962d2e026d0
34 lines
769 B
Go
34 lines
769 B
Go
package main
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"gopkg.in/kataras/iris.v6"
|
|
"gopkg.in/kataras/iris.v6/adaptors/httprouter"
|
|
)
|
|
|
|
func main() {
|
|
app := iris.New()
|
|
// output startup banner and error logs on os.Stdout
|
|
app.Adapt(iris.DevLogger())
|
|
// set the router, you can choose gorillamux too
|
|
app.Adapt(httprouter.New())
|
|
|
|
app.Get("/", func(ctx *iris.Context) {
|
|
ctx.Writef("Hello from the server")
|
|
})
|
|
|
|
app.Get("/mypath", func(ctx *iris.Context) {
|
|
ctx.Writef("Hello from %s", ctx.Path())
|
|
})
|
|
|
|
// call .Boot before use the 'app' as an http.Handler on a custom http.Server
|
|
app.Boot()
|
|
|
|
// create our custom fasthttp server and assign the Handler/Router
|
|
fsrv := &http.Server{Handler: app, Addr: ":8080"}
|
|
fsrv.ListenAndServe()
|
|
|
|
// navigate to http://127.0.0.1:8080/mypath
|
|
}
|