app.Run() for simple cases and app.RunGraceful() when you need to finish in-flight requests before the process exits.
app.Run()
app.Run() starts the server and blocks until the server encounters an error. Pass an address string to bind to a specific host and port.
When you call
app.Run() with no arguments, the server listens on :6789 by default. You can also override the port by setting the PORT environment variable.app.Run() does not handle OS signals. Sending SIGINT (Ctrl+C) or SIGTERM terminates the process immediately without waiting for active connections to complete.
app.RunGraceful()
app.RunGraceful(shutdownTimeout, address) listens for SIGINT and SIGTERM. When either signal arrives, it calls the underlying server’s shutdown method and waits up to shutdownTimeout seconds for active connections to finish.
shutdownTimeout is zero or negative, it defaults to 5 seconds.
Like app.Run(), the address argument is optional — omit it to fall back to :6789.
app.Shutdown()
Call app.Shutdown() to trigger a graceful shutdown programmatically (for example, from a signal handler you manage yourself or from a test).
Shutdown() before the server has started is a no-op.
Complete Example
kill <pid>, you will see: