v0.0.640 add error return parameter to GinWrapper.ListenAndServeHTTP
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m30s
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m30s
This commit is contained in:
+25
-25
@@ -2,17 +2,19 @@ package ginext
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/mathext"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/rext"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/exerr"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/langext"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/mathext"
|
||||
"git.blackforestbytes.com/BlackForestBytes/goext/rext"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type GinWrapper struct {
|
||||
@@ -103,7 +105,10 @@ func NewEngine(opt Options) *GinWrapper {
|
||||
return wrapper
|
||||
}
|
||||
|
||||
func (w *GinWrapper) ListenAndServeHTTP(addr string, postInit func(port string)) (chan error, *http.Server) {
|
||||
// ListenAndServeHTTP
|
||||
// returns nil, nil, err if something went wrong during init
|
||||
// returns $chan, $server, nil if init was successful ( later errors come through chan )
|
||||
func (w *GinWrapper) ListenAndServeHTTP(addr string, postInit func(port string)) (chan error, *http.Server, error) {
|
||||
|
||||
w.DebugPrintRoutes()
|
||||
|
||||
@@ -114,30 +119,25 @@ func (w *GinWrapper) ListenAndServeHTTP(addr string, postInit func(port string))
|
||||
|
||||
errChan := make(chan error)
|
||||
|
||||
go func() {
|
||||
ln, err := net.Listen("tcp", httpserver.Addr)
|
||||
if err != nil {
|
||||
return nil, nil, exerr.Wrap(err, "").Build()
|
||||
}
|
||||
|
||||
ln, err := net.Listen("tcp", httpserver.Addr)
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
_, port, err := net.SplitHostPort(ln.Addr().String())
|
||||
if err != nil {
|
||||
return nil, nil, exerr.Wrap(err, "").Build()
|
||||
}
|
||||
|
||||
_, port, err := net.SplitHostPort(ln.Addr().String())
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
log.Info().Str("address", httpserver.Addr).Msg("HTTP-Server started on http://localhost:" + port)
|
||||
|
||||
log.Info().Str("address", httpserver.Addr).Msg("HTTP-Server started on http://localhost:" + port)
|
||||
if postInit != nil {
|
||||
postInit(port) // the net.Listener a few lines above is at this point actually already buffering requests
|
||||
}
|
||||
|
||||
if postInit != nil {
|
||||
postInit(port) // the net.Listener a few lines above is at this point actually already buffering requests
|
||||
}
|
||||
go func() { errChan <- httpserver.Serve(ln) }()
|
||||
|
||||
errChan <- httpserver.Serve(ln)
|
||||
}()
|
||||
|
||||
return errChan, httpserver
|
||||
return errChan, httpserver, nil
|
||||
}
|
||||
|
||||
func (w *GinWrapper) DebugPrintRoutes() {
|
||||
|
||||
Reference in New Issue
Block a user