mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-06 02:36:49 +00:00
set debug
This commit is contained in:
parent
efccace761
commit
691b724189
2 changed files with 17 additions and 7 deletions
|
|
@ -8,7 +8,6 @@ import (
|
|||
"net/http"
|
||||
"os"
|
||||
"os/signal"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/a-h/templ"
|
||||
|
|
@ -31,8 +30,9 @@ type Server struct {
|
|||
}
|
||||
|
||||
type options struct {
|
||||
port *int
|
||||
fs *embed.FS
|
||||
port *int
|
||||
fs *embed.FS
|
||||
debug *bool
|
||||
}
|
||||
|
||||
type Option func(*options) error
|
||||
|
|
@ -54,6 +54,13 @@ func WithFileSystem(fs embed.FS) Option {
|
|||
}
|
||||
}
|
||||
|
||||
func WithDebug(debug bool) Option {
|
||||
return func(o *options) error {
|
||||
o.debug = &debug
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func New(bs *booking.Service, ps *pdf.PdfService, hc *config.Host, opts ...Option) (*Server, error) {
|
||||
option := new(options)
|
||||
for _, opt := range opts {
|
||||
|
|
@ -64,7 +71,7 @@ func New(bs *booking.Service, ps *pdf.PdfService, hc *config.Host, opts ...Optio
|
|||
}
|
||||
|
||||
s := &Server{
|
||||
Router: NewRouter(*option.fs),
|
||||
Router: NewRouter(*option.fs, *option.debug),
|
||||
bs: bs,
|
||||
ps: ps,
|
||||
hc: hc,
|
||||
|
|
@ -103,11 +110,11 @@ func renderTempl(c echo.Context, status int, t templ.Component) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func NewRouter(fs embed.FS) *echo.Echo {
|
||||
func NewRouter(fs embed.FS, debug bool) *echo.Echo {
|
||||
e := echo.New()
|
||||
// config
|
||||
e.HideBanner = true
|
||||
e.Debug = strings.ToLower(os.Getenv("DEBUG")) == "true"
|
||||
e.Debug = debug
|
||||
e.HTTPErrorHandler = func(err error, c echo.Context) {
|
||||
if hub := sentryecho.GetHubFromContext(c); hub != nil {
|
||||
hub.WithScope(func(s *sentry.Scope) {
|
||||
|
|
|
|||
5
main.go
5
main.go
|
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
"os/signal"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/joho/godotenv"
|
||||
|
|
@ -65,7 +66,9 @@ func run(ctx context.Context, getEnv func(string) string) error {
|
|||
if err != nil {
|
||||
return fmt.Errorf("error parsing PORT env %s\n", err)
|
||||
}
|
||||
srv, err := server.New(booking.NewService(db), ps, config.NewHost(), server.WithPort(port), server.WithFileSystem(static))
|
||||
srv, err := server.New(
|
||||
booking.NewService(db), ps, config.NewHost(),
|
||||
server.WithPort(port), server.WithFileSystem(static), server.WithDebug(strings.ToLower(getEnv("DEBUG")) == "true"))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error starting server %s\n", err)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue