shortcut of app.Run(iris.Addr(...)) is app.Listen

Gerasimos (Makis) Maropoulos 2020-03-06 11:48:57 +02:00
parent 5eaf71b17b
commit adf5d2bd91
No known key found for this signature in database
GPG Key ID: 5DBE766BD26A54E7
23 changed files with 40 additions and 38 deletions

@ -20,7 +20,7 @@ Follow the steps below to, temporarily, convert your local Iris web server to a
Full `Tunneling` configuration:
```go
app.Run(iris.Addr(":8080"), iris.WithConfiguration(
app.Listen(":8080", iris.WithConfiguration(
iris.Configuration{
Tunneling: iris.TunnelingConfiguration{
AuthToken: "my-ngrok-auth-client-token",

@ -21,7 +21,7 @@ config := iris.WithConfiguration(iris.Configuration {
Charset: "UTF-8",
})
app.Run(iris.Addr(":8080"), config)
app.Listen(":8080", config)
```
### Load from [YAML](https://yaml.org/)
@ -41,7 +41,7 @@ File: **main.go**
```go
config := iris.WithConfiguration(iris.YAML("./iris.yml"))
app.Run(iris.Addr(":8080"), config)
app.Listen(":8080", config)
```
### Load from [TOML](https://github.com/toml-lang/toml)
@ -65,7 +65,7 @@ File: **main.go**
```go
config := iris.WithConfiguration(iris.TOML("./iris.tml"))
app.Run(iris.Addr(":8080"), config)
app.Listen(":8080", config)
```
## Using the functional way
@ -73,7 +73,7 @@ app.Run(iris.Addr(":8080"), config)
As we already mention, you can pass any number of `iris.Configurator` in the `app.Run`s second argument. Iris provides an option for each of its `iris.Configuration`s fields.
```go
app.Run(iris.Addr(":8080"), iris.WithoutInterruptHandler,
app.Listen(":8080", iris.WithoutInterruptHandler,
iris.WithoutServerError(iris.ErrServerClosed),
iris.WithoutBodyConsumptionOnUnmarshal,
iris.WithoutAutoFireStatusCode,
@ -91,7 +91,7 @@ configuration options without even a glitch to the documentation.
The `iris.Configuration` contains a field called `Other map[string]interface{}` which accepts any custom `key:value` option, therefore you can use that field to pass specific values that your app expects based on the custom requirements.
```go
app.Run(iris.Addr(":8080"),
app.Listen(":8080",
iris.WithOtherValue("ServerName", "my amazing iris server"),
iris.WithOtherValue("ServerOwner", "admin@example.com"),
)

@ -48,7 +48,7 @@ app := iris.New()
app.HandleDir("/static", "./assets")
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
```
Now, if you want to embed the static files to be lived inside the executable build in order to not depend on a system directory you can use a tool like [go-bindata](https://github.com/go-bindata/go-bindata) to convert the files into `[]byte` inside your program. Let's take a quick tutorial on this and how Iris helps to serve those data.

@ -97,7 +97,7 @@ func main() {
})
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```
@ -125,7 +125,7 @@ func main() {
id, page, name, message)
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```
@ -183,7 +183,7 @@ func main() {
ctx.UploadFormFiles("./uploads", beforeSave)
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
func beforeSave(ctx iris.Context, file *multipart.FileHeader) {

@ -19,7 +19,7 @@ func main() {
// Listens and serves incoming http requests
// on http://localhost:8080.
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
func myMiddleware(ctx iris.Context) {
@ -75,7 +75,7 @@ func main() {
})
// Start the server using a network address.
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```

@ -71,7 +71,7 @@ func main() {
}
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```

12
Host.md

@ -8,8 +8,10 @@ by passing a network address with form of "hostname:ip". With Iris
we use the `iris.Addr` which is an `iris.Runner` type
```go
// Listening on tcp with network address 0.0.0.0:8080
app.Run(iris.Addr(":8080"))
// Listening on tcp with network address 0.0.0.0:8080.
//
// Listen is a shortcut for app.Run(iris.Addr(":8080")).
app.Listen(":8080")
```
Sometimes you have created a standard net/http server somewhere else in your app and want to use that to serve the Iris web app
@ -165,7 +167,7 @@ app.ConfigureHost(func(h *iris.Supervisor) {
println("server terminated")
})
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
```
Access to all hosts that serve your application can be provided by
@ -200,7 +202,7 @@ app := iris.New()
app.Get("/", indexHandler)
// run in different goroutine in order to not block the main "goroutine".
go app.Run(iris.Addr(":8080"))
go app.Listen(":8080")
// start a second server which is listening on tcp 0.0.0.0:9090,
// without "go" keyword because we want to block at the last server-run.
app.NewHost(&http.Server{Addr:":9090"}).ListenAndServe()
@ -245,7 +247,7 @@ func main() {
ctx.HTML(" <h1>hi, I just exist in order to see if the server is closed</h1>")
})
app.Run(iris.Addr(":8080"), iris.WithoutInterruptHandler)
app.Listen(":8080", iris.WithoutInterruptHandler)
}
```

@ -235,7 +235,7 @@ func main() {
// or http://localhost:8080/other?lang=en-US
//
// or use cookies to set the language.
app.Run(iris.Addr(":8080"), iris.WithSitemap("http://localhost:8080"))
app.Listen(":8080", iris.WithSitemap("http://localhost:8080"))
}
```

4
MVC.md

@ -33,7 +33,7 @@ import (
func main() {
app := iris.New()
mvc.Configure(app.Party("/root"), myMVC)
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
func myMVC(app *mvc.Application) {
@ -192,7 +192,7 @@ func main() {
// http://localhost:8080/ping
// http://localhost:8080/hello
// http://localhost:8080/custom_path
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
// ExampleController serves the "/", "/ping" and "/hello".

@ -91,7 +91,7 @@ func main() {
// [save user to database...]
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
func UserStructLevelValidation(sl validator.StructLevel) {

@ -65,7 +65,7 @@ func main(){
app.Get("/", getTokenHandler)
app.Get("/secured", j.Serve, myAuthenticatedHandler)
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```

@ -20,7 +20,7 @@ func main(){
// defaults to < 200 || >= 400:
// app.OnAnyErrorCode(handler)
app.Get("/", index)
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
func notFound(ctx iris.Context) {

@ -15,7 +15,7 @@ func main() {
app := iris.New()
// or app.Use(before) and app.Done(after).
app.Get("/", before, mainHandler, after)
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
func before(ctx iris.Context) {
@ -80,7 +80,7 @@ func main() {
app.UseGlobal(before)
app.DoneGlobal(after)
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
func before(ctx iris.Context) {

@ -90,7 +90,7 @@ func main() {
ctx.View("hi.html")
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
// Should always print "($PATH) Handler is executing from 'MyContext'"

@ -156,7 +156,7 @@ func main() {
ctx.WriteString(message)
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```

@ -25,7 +25,7 @@ func main() {
app.Get("/about", h).Name = "about"
app.Get("/page/{id}", h).Name = "page"
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```

@ -44,7 +44,7 @@ admin.Get("/hey", func(ctx iris.Context) {
// [other routes here...]
app.Run(iris.Addr("mydomain.com:80"))
app.Listen("mydomain.com:80")
```
For local development you'll have to edit your hosts, for example in windows operating system open the `C:\Windows\System32\Drivers\etc\hosts` file and append:

@ -95,7 +95,7 @@ func main() {
// http://localhost:8080/css/main.css
// http://localhost:8080/profile/anyusername
// http://localhost:8080/other/random
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
// Note: In this example we just saw one use case,
// you may want to .WrapRouter or .Downgrade in order to

@ -38,13 +38,13 @@ However, if you want to **disable path correction** for the requested resources
// [app := iris.New...]
// [...]
app.Run(iris.Addr(":8080"), iris.WithoutPathCorrection)
app.Listen(":8080", iris.WithoutPathCorrection)
```
If you want to keep the same handler and route for `/api/user` and `/api/user/` paths **without redirection**(common scenario) use just the `iris.WithoutPathCorrectionRedirection` option instead:
```go
app.Run(iris.Addr(":8080"), iris.WithoutPathCorrectionRedirection)
app.Listen(":8080", iris.WithoutPathCorrectionRedirection)
```
## API
@ -165,7 +165,7 @@ func main() {
ctx.Exec("GET", "/invisible/iris")
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```

@ -185,7 +185,7 @@ func main() {
app.Get("/login", login)
app.Get("/logout", logout)
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```

@ -6,7 +6,7 @@ To enable sitemaps on your web application you should use the `iris.WithSitemap`
app := iris.New()
// [...]
app.Run(iris.Addr(":8080"), iris.WithSitemap("http://localhost:8080"))
app.Listen(":8080", iris.WithSitemap("http://localhost:8080"))
```
The application will loop through registered _static_ routes and it will add each one of them to the sitemap file. By default only the `<loc>` XML element will be filled unless the route's fields `LastMod`, `ChangeFreq` or/and `Priority`[*](https://www.sitemaps.org/protocol.html) are set.

@ -51,7 +51,7 @@ func h(ctx iris.Context) {
func main() {
app := newApp()
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```

@ -114,7 +114,7 @@ func main() {
ctx.View("hi.html")
})
app.Run(iris.Addr(":8080"))
app.Listen(":8080")
}
```