MCPcopy Create free account
hub / github.com/kataras/iris / main

Function main

_examples/http-server/custom-httpserver/std-way/main.go:9–40  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

7)
8
9func 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}

Callers

nothing calls this directly

Calls 6

NewMethod · 0.80
WritefMethod · 0.80
ListenAndServeMethod · 0.80
GetMethod · 0.65
PathMethod · 0.65
BuildMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…