Skip to content

Commit

Permalink
errors are now reported via runtime panics, slightly updated docstrin…
Browse files Browse the repository at this point in the history
…gs and comments
  • Loading branch information
flrdv committed Nov 6, 2024
1 parent 19113b9 commit ea9e075
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions indi.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package indigo

import (
"crypto/tls"
"github.com/indigo-web/indigo/config"
"github.com/indigo-web/indigo/internal/strutil"
"github.com/indigo-web/indigo/router"
Expand Down Expand Up @@ -57,7 +58,8 @@ func (a *App) OnStop(cb func()) *App {
func (a *App) Listen(addr string, ts ...Transport) *App {
if len(addr) == 0 {
// empty addr is considered a no-op Bind operation. Main use-case is omitting
// default TCP binding when, for example, TLS-only mode is desired
// default TCP binding when, for example, the default TCP listener is preferred
// to be disabled
return a
}

Expand All @@ -75,12 +77,12 @@ func (a *App) Listen(addr string, ts ...Transport) *App {
return a
}

// TLS is a shortcut for App.Bind(addr, TLS(cert, key)).
// TLS is a shortcut for App.Listen(addr, indigo.TLS(indigo.Cert(cert, key))).
//
// Starts an TLS listener on the provided port using passed cert and key files.
// If those are incorrect, it will be reported when the application starts.
func (a *App) TLS(addr string, cert, key string) *App {
return a.Listen(addr, TLS(cert, key))
// Starts an TLS listener on the provided address using provided 1 or more certificates.
// Zero passed certificates will panic.
func (a *App) TLS(addr string, certs ...tls.Certificate) *App {
return a.Listen(addr, TLS(certs...))
}

// Serve starts the web-application. If nil is passed instead of a router, empty inbuilt will
Expand All @@ -96,14 +98,6 @@ func (a *App) Serve(r router.Fabric) error {
func (a *App) run(r router.Router) error {
callIfNotNil(a.hooks.OnStart)

// if any error occurred during transports registration, it's easier to
// report it before any transport will be started
for _, t := range a.transports {
if t.error != nil {
return t.error
}
}

for _, t := range a.transports {
if err := a.supervisor.Add(t.addr, t.inner, t.spawnCallback(a.cfg, r)); err != nil {
return err
Expand All @@ -114,7 +108,7 @@ func (a *App) run(r router.Router) error {
}
}

err := a.supervisor.Run(a.cfg.TCP)
err := a.supervisor.Run(a.cfg.NET)
callIfNotNil(a.hooks.OnStop)

return err
Expand Down

0 comments on commit ea9e075

Please sign in to comment.