mirror of
https://github.com/kataras/iris.git
synced 2025-12-25 13:57:04 +00:00
don't fire ErrServerClosed on manually interrupt signals (CTRL/CMD+C)
Former-commit-id: 673c84dd13bb99c0926aa1b4a6b4eff9745403d8
This commit is contained in:
@@ -4,5 +4,5 @@ go 1.13
|
||||
|
||||
require (
|
||||
github.com/betacraft/yaag v1.0.1-0.20191027021412-565f65e36090
|
||||
github.com/kataras/iris/v12 v12.1.5
|
||||
github.com/kataras/iris/v12 v12.1.8
|
||||
)
|
||||
|
||||
@@ -38,5 +38,5 @@ func main() {
|
||||
// http://localhost:8080
|
||||
// http://localhost:8080/ping
|
||||
// http://localhost:8080/hello
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -50,8 +50,6 @@ func main() {
|
||||
app.Run(
|
||||
// Start the web server at localhost:8080
|
||||
iris.Addr("localhost:8080"),
|
||||
// skip err server closed when CTRL/CMD+C pressed:
|
||||
iris.WithoutServerError(iris.ErrServerClosed),
|
||||
// enables faster json serialization and more:
|
||||
iris.WithOptimizations,
|
||||
)
|
||||
|
||||
@@ -32,8 +32,5 @@ func main() {
|
||||
// Path: http://localhost:8080
|
||||
app.Get("/", indexHandler)
|
||||
|
||||
app.Run(
|
||||
iris.Addr(":8080"),
|
||||
iris.WithoutServerError(iris.ErrServerClosed),
|
||||
)
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -235,7 +235,7 @@ func main() {
|
||||
app := iris.New()
|
||||
|
||||
iris.RegisterOnInterrupt(func() {
|
||||
timeout := 5 * time.Second
|
||||
timeout := 10 * time.Second
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
// close all hosts
|
||||
|
||||
@@ -33,7 +33,7 @@ func main() {
|
||||
case <-ch:
|
||||
println("shutdown...")
|
||||
|
||||
timeout := 5 * time.Second
|
||||
timeout := 10 * time.Second
|
||||
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
|
||||
defer cancel()
|
||||
app.Shutdown(ctx)
|
||||
|
||||
@@ -18,7 +18,7 @@ func main() {
|
||||
app := iris.New()
|
||||
|
||||
iris.RegisterOnInterrupt(func() {
|
||||
timeout := 5 * time.Second
|
||||
timeout := 10 * time.Second
|
||||
ctx, cancel := stdContext.WithTimeout(stdContext.Background(), timeout)
|
||||
defer cancel()
|
||||
// close all hosts
|
||||
|
||||
@@ -17,7 +17,8 @@ func main() {
|
||||
}
|
||||
// same as:
|
||||
// err := app.Listen(":8080")
|
||||
// if err != nil && (err != iris.ErrServerClosed || err.Error() != iris.ErrServerClosed.Error()) {
|
||||
// import "errors"
|
||||
// if errors.Is(err, iris.ErrServerClosed) {
|
||||
// [...]
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -60,9 +60,8 @@ func TestListenAddrWithoutServerErr(t *testing.T) {
|
||||
app.Shutdown(ctx)
|
||||
}()
|
||||
|
||||
// we disable the ErrServerClosed, so the error should be nil when server is closed by `app.Shutdown`.
|
||||
|
||||
// so in this case the iris/http.ErrServerClosed should be NOT logged and NOT return.
|
||||
// we disable the ErrServerClosed, so the error should be nil when server is closed by `app.Shutdown`
|
||||
// or by an external issue.
|
||||
err := app.Listen(":9827", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
if err != nil {
|
||||
t.Fatalf("expecting err to be nil but got: %v", err)
|
||||
|
||||
@@ -11,14 +11,14 @@ func main() {
|
||||
app := iris.New()
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.HTML("<h1>Hello, try to refresh the page after ~10 secs</h1>")
|
||||
ctx.HTML("<h1>Hello, try to refresh the page after ~5 secs</h1>")
|
||||
})
|
||||
|
||||
app.Logger().Info("Wait 10 seconds and check your terminal again")
|
||||
app.Logger().Info("Wait 5 seconds and check your terminal again")
|
||||
// simulate a shutdown action here...
|
||||
go func() {
|
||||
<-time.After(10 * time.Second)
|
||||
timeout := 5 * time.Second
|
||||
<-time.After(5 * time.Second)
|
||||
timeout := 10 * time.Second
|
||||
ctx, cancel := context.WithTimeout(context.Background(), timeout)
|
||||
defer cancel()
|
||||
// close all hosts, this will notify the callback we had register
|
||||
@@ -36,21 +36,24 @@ func main() {
|
||||
// wait 10 seconds and check your terminal.
|
||||
app.Run(iris.Addr(":8080", configureHost), iris.WithoutServerError(iris.ErrServerClosed))
|
||||
|
||||
/*
|
||||
Or for simple cases you can just use the:
|
||||
iris.RegisterOnInterrupt for global catch of the CTRL/CMD+C and OS events.
|
||||
Look at the "graceful-shutdown" example for more.
|
||||
time.Sleep(500 * time.Millisecond) // give time to the separate go routine(`onServerShutdown`) to finish.
|
||||
|
||||
/* See
|
||||
iris.RegisterOnInterrupt(callback) for global catch of the CTRL/CMD+C and OS events.
|
||||
Look at the "graceful-shutdown" example for more.
|
||||
*/
|
||||
}
|
||||
|
||||
func onServerShutdown() {
|
||||
println("server is closed")
|
||||
}
|
||||
|
||||
func configureHost(su *iris.Supervisor) {
|
||||
// here we have full access to the host that will be created
|
||||
// inside the `app.Run` function or `NewHost`.
|
||||
//
|
||||
// we're registering a shutdown "event" callback here:
|
||||
su.RegisterOnShutdown(func() {
|
||||
println("server is closed")
|
||||
})
|
||||
su.RegisterOnShutdown(onServerShutdown)
|
||||
// su.RegisterOnError
|
||||
// su.RegisterOnServe
|
||||
}
|
||||
|
||||
@@ -24,5 +24,5 @@ func main() {
|
||||
|
||||
// http://localhost:8080?referer=https://twitter.com/Xinterio/status/1023566830974251008
|
||||
// http://localhost:8080?referer=https://www.google.com/search?q=Top+6+golang+web+frameworks&oq=Top+6+golang+web+frameworks
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func main() {
|
||||
//
|
||||
// The response should be:
|
||||
// Received: main.config{Addr:"localhost:8080", ServerName:"Iris"}
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed), iris.WithOptimizations)
|
||||
app.Listen(":8080", iris.WithOptimizations)
|
||||
}
|
||||
|
||||
func newApp() *iris.Application {
|
||||
|
||||
@@ -19,7 +19,7 @@ func main() {
|
||||
//
|
||||
// The response should be:
|
||||
// Received: main.config{Addr:"localhost:8080", ServerName:"Iris"}
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed), iris.WithOptimizations)
|
||||
app.Listen(":8080", iris.WithOptimizations)
|
||||
}
|
||||
|
||||
func newApp() *iris.Application {
|
||||
|
||||
@@ -60,5 +60,5 @@ func main() {
|
||||
//
|
||||
// The response should be:
|
||||
// Received: main.Company{Name:"iris-Go", City:"New York", Other:"Something here"}
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed), iris.WithOptimizations)
|
||||
app.Listen(":8080", iris.WithOptimizations)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ func main() {
|
||||
//
|
||||
// The response should be:
|
||||
// Received: main.person{XMLName:xml.Name{Space:"", Local:"person"}, Name:"Winston Churchill", Age:90, Description:"Description of this person, the body of this inner element."}
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed), iris.WithOptimizations)
|
||||
app.Listen(":8080", iris.WithOptimizations)
|
||||
}
|
||||
|
||||
func newApp() *iris.Application {
|
||||
|
||||
@@ -61,5 +61,5 @@ func main() {
|
||||
// http://localhost:8080/2
|
||||
// http://lcoalhost:8080/notfoundhere
|
||||
// see the output on the console.
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func main() {
|
||||
// http://localhost:8080/1
|
||||
// http://localhost:8080/2
|
||||
// http://lcoalhost:8080/notfoundhere
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
var excludeExtensions = [...]string{
|
||||
|
||||
@@ -35,7 +35,7 @@ func main() {
|
||||
// http://localhost:8080/1
|
||||
// http://localhost:8080/2
|
||||
// http://lcoalhost:8080/notfoundhere
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
// get a filename based on the date, file logs works that way the most times
|
||||
|
||||
@@ -18,5 +18,5 @@ func main() {
|
||||
app := newApp()
|
||||
// http://localhost:8080
|
||||
// http://localhost:8080/yourname
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func main() {
|
||||
})
|
||||
}() // ...
|
||||
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
/* For a golang SSE client you can look at: https://github.com/r3labs/sse#example-client */
|
||||
|
||||
@@ -187,5 +187,5 @@ func main() {
|
||||
|
||||
// http://localhost:8080
|
||||
// http://localhost:8080/events
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -113,5 +113,5 @@ func main() {
|
||||
//
|
||||
// `iris.WithoutServerError` is an optional configurator,
|
||||
// if passed to the `Run` then it will not print its passed error as an actual server error.
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed), iris.WithOptimizations)
|
||||
app.Listen(":8080", iris.WithOptimizations)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ func main() {
|
||||
|
||||
// Navigate to http://localhost:8080/ping
|
||||
// and open the ./logs{TODAY}.txt file.
|
||||
if err := app.Listen(":8080", iris.WithoutBanner, iris.WithoutServerError(iris.ErrServerClosed)); err != nil {
|
||||
if err := app.Listen(":8080", iris.WithoutBanner); err != nil {
|
||||
app.Logger().Warn("Shutdown with error: " + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ func main() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
resp, err := client.Post("https://localhost/hello", "application/json", buf)
|
||||
resp, err := client.Post("https://localhost/helloworld.Greeter/SayHello", "application/json", buf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ func main() {
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
// The Iris server should ran under TLS (it's a gRPC requirement).
|
||||
// POST: https://localhost:443/helloworld.greeter/sayhello
|
||||
// POST: https://localhost:443/helloworld.Greeter/SayHello
|
||||
// with request data: {"name": "John"}
|
||||
// and expected output: {"message": "Hello John"}
|
||||
app.Run(iris.TLS(":443", "server.crt", "server.key"))
|
||||
@@ -32,7 +32,6 @@ func main() {
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
// app.Configure(iris.WithLowercaseRouting) // OPTIONAL.
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.HTML("<h1>Index Page</h1>")
|
||||
@@ -55,7 +54,9 @@ func newApp() *iris.Application {
|
||||
return app
|
||||
}
|
||||
|
||||
type myController struct{}
|
||||
type myController struct {
|
||||
// Ctx iris.Context
|
||||
}
|
||||
|
||||
// SayHello implements helloworld.GreeterServer.
|
||||
func (c *myController) SayHello(ctx context.Context, in *pb.HelloRequest) (*pb.HelloReply, error) {
|
||||
|
||||
@@ -76,12 +76,8 @@ func main() {
|
||||
// http://localhost:8080/user/me
|
||||
// http://localhost:8080/user/logout
|
||||
// basic auth: "admin", "password", see "./middleware/basicauth.go" source file.
|
||||
app.Run(
|
||||
// Starts the web server at localhost:8080
|
||||
iris.Addr("localhost:8080"),
|
||||
// Ignores err server closed log when CTRL/CMD+C pressed.
|
||||
iris.WithoutServerError(iris.ErrServerClosed),
|
||||
// Enables faster json serialization and more.
|
||||
iris.WithOptimizations,
|
||||
)
|
||||
|
||||
// Starts the web server at localhost:8080
|
||||
// Enables faster json serialization and more.
|
||||
app.Listen(":8080", iris.WithOptimizations)
|
||||
}
|
||||
|
||||
@@ -30,14 +30,7 @@ func main() {
|
||||
// http://localhost:8080/hello/iris
|
||||
// http://localhost:8080/movies
|
||||
// http://localhost:8080/movies/1
|
||||
app.Run(
|
||||
// Start the web server at localhost:8080
|
||||
iris.Addr("localhost:8080"),
|
||||
// skip err server closed when CTRL/CMD+C pressed:
|
||||
iris.WithoutServerError(iris.ErrServerClosed),
|
||||
// enables faster json serialization and more:
|
||||
iris.WithOptimizations,
|
||||
)
|
||||
app.Listen(":8080", iris.WithOptimizations)
|
||||
}
|
||||
|
||||
// note the mvc.Application, it's not iris.Application.
|
||||
|
||||
@@ -165,7 +165,8 @@ func main() {
|
||||
"data": user.Serializer(),
|
||||
})
|
||||
})
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
type patchParam struct {
|
||||
|
||||
@@ -70,5 +70,5 @@ func main() {
|
||||
|
||||
// http://localhost:8080/insert
|
||||
// http://localhost:8080/get
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -98,5 +98,5 @@ func main() {
|
||||
myCustomRouter := new(customRouter)
|
||||
app.BuildRouter(app.ContextPool, myCustomRouter, app.APIBuilder, true)
|
||||
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func main() {
|
||||
// this will handle only GET "/other2/static"
|
||||
app.Get("/other2/static2", staticPathOther2)
|
||||
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
func h(ctx iris.Context) {
|
||||
|
||||
@@ -104,5 +104,5 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -105,5 +105,5 @@ func main() {
|
||||
}
|
||||
})
|
||||
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ func main() {
|
||||
// POST, GET: http://localhost:8080/api/v1/topics
|
||||
// POST : http://localhost:8080/apiv1/topics/{topic}/produce?key=my-key
|
||||
// GET : http://localhost:8080/apiv1/topics/{topic}/consume?partition=0&offset=0 (these url query parameters are optional)
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
// simple use-case, you can use templates and views obviously, see the "_examples/views" examples.
|
||||
|
||||
@@ -116,5 +116,5 @@ func main() {
|
||||
// serves the npm browser websocket client usage example.
|
||||
app.HandleDir("/browserify", "./browserify")
|
||||
|
||||
app.Listen(":8080", iris.WithoutServerError(iris.ErrServerClosed))
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
@@ -3,6 +3,6 @@ module github.com/kataras/iris/_examples/websocket/socketio
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/googollee/go-socket.io v1.4.3-0.20191109153049-7451e2f8c2e0 // indirect
|
||||
github.com/kataras/iris/v12 v12.1.5
|
||||
github.com/googollee/go-socket.io v1.4.3-0.20191109153049-7451e2f8c2e0
|
||||
github.com/kataras/iris/v12 v12.1.8
|
||||
)
|
||||
|
||||
@@ -47,10 +47,8 @@ func main() {
|
||||
|
||||
app.HandleMany("GET POST", "/socket.io/{any:path}", iris.FromStd(server))
|
||||
app.HandleDir("/", "./asset")
|
||||
app.Listen(":8000",
|
||||
iris.WithoutPathCorrection,
|
||||
iris.WithoutServerError(iris.ErrServerClosed),
|
||||
)
|
||||
|
||||
app.Listen(":8000", iris.WithoutPathCorrection)
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user