Skip to content

Commit

Permalink
feat: add environment to ctrl
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Aug 26, 2024
1 parent aca65cd commit e7dd1e8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
11 changes: 11 additions & 0 deletions ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/gofiber/fiber/v2"
goth "github.com/zeiss/fiber-goth"
"github.com/zeiss/fiber-goth/adapters"
reload "github.com/zeiss/fiber-reload"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -195,6 +196,16 @@ func (c *DefaultController) Ctx() *fiber.Ctx {
return c.ctx
}

// IsDevelopment returns true if the environment is development.
func (c *DefaultController) IsDevelopment() bool {
return reload.IsDevelopment(c.ctx.UserContext())
}

// IsProduction returns true if the environment is production.
func (c *DefaultController) IsProduction() bool {
return reload.IsProduction(c.ctx.UserContext())
}

// Redirect redirects to the given path.
func (c *DefaultController) Redirect(path string) error {
Redirect(c.ctx, path)
Expand Down
10 changes: 7 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
module github.com/zeiss/fiber-htmx

go 1.22.1
go 1.23

toolchain go1.22.5
toolchain go1.23.0

require (
github.com/ettle/strcase v0.2.0
Expand All @@ -20,7 +20,7 @@ require (
github.com/yuin/goldmark v1.7.4
github.com/zeiss/fiber-authz v1.0.33
github.com/zeiss/fiber-goth v1.2.11
github.com/zeiss/pkg v0.1.8-0.20240820122414-ce95f079ee32
github.com/zeiss/pkg v0.1.8-0.20240823051228-d40ebe6703e0
gorm.io/gorm v1.25.11
mvdan.cc/gofumpt v0.7.0
)
Expand Down Expand Up @@ -65,6 +65,7 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/denis-tingaikin/go-header v0.5.0 // indirect
github.com/fasthttp/websocket v1.5.8 // indirect
github.com/fatih/color v1.17.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/firefart/nonamedreturns v1.0.5 // indirect
Expand All @@ -89,6 +90,7 @@ require (
github.com/go-xmlfmt/xmlfmt v1.1.2 // indirect
github.com/gobwas/glob v0.2.3 // indirect
github.com/goccy/go-json v0.10.3 // indirect
github.com/gofiber/contrib/websocket v1.3.2 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/golangci/dupl v0.0.0-20180902072040-3e9179ac440a // indirect
github.com/golangci/gofmt v0.0.0-20240816233607-d8596aa466a9 // indirect
Expand Down Expand Up @@ -180,6 +182,7 @@ require (
github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 // indirect
github.com/sashamelentyev/interfacebloat v1.1.0 // indirect
github.com/sashamelentyev/usestdlibvars v1.27.0 // indirect
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 // indirect
github.com/securego/gosec/v2 v2.20.1-0.20240822074752-ab3f6c1c83a0 // indirect
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
Expand Down Expand Up @@ -210,6 +213,7 @@ require (
github.com/yagipy/maintidx v1.0.0 // indirect
github.com/yeya24/promlinter v0.3.0 // indirect
github.com/ykadowak/zerologlint v0.1.5 // indirect
github.com/zeiss/fiber-reload v0.1.0 // indirect
gitlab.com/bosi/decorder v0.4.2 // indirect
go-simpler.org/musttag v0.12.2 // indirect
go-simpler.org/sloglint v0.7.2 // indirect
Expand Down
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ github.com/denis-tingaikin/go-header v0.5.0 h1:SRdnP5ZKvcO9KKRP1KJrhFR3RrlGuD+42
github.com/denis-tingaikin/go-header v0.5.0/go.mod h1:mMenU5bWrok6Wl2UsZjy+1okegmwQ3UgWl4V1D8gjlY=
github.com/ettle/strcase v0.2.0 h1:fGNiVF21fHXpX1niBgk0aROov1LagYsOwV/xqKDKR/Q=
github.com/ettle/strcase v0.2.0/go.mod h1:DajmHElDSaX76ITe3/VHVyMin4LWSJN5Z909Wp+ED1A=
github.com/fasthttp/websocket v1.5.8 h1:k5DpirKkftIF/w1R8ZzjSgARJrs54Je9YJK37DL/Ah8=
github.com/fasthttp/websocket v1.5.8/go.mod h1:d08g8WaT6nnyvg9uMm8K9zMYyDjfKyj3170AtPRuVU0=
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
github.com/fatih/structtag v1.2.0 h1:/OdNE99OxoI/PqaW/SuSK9uxxT3f/tcSZgon/ssNSx4=
Expand Down Expand Up @@ -152,6 +154,8 @@ github.com/gobwas/glob v0.2.3 h1:A4xDbljILXROh+kObIiy5kIaPYD8e96x1tgBhUI5J+Y=
github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJAkT8=
github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA=
github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M=
github.com/gofiber/contrib/websocket v1.3.2 h1:AUq5PYeKwK50s0nQrnluuINYeep1c4nRCJ0NWsV3cvg=
github.com/gofiber/contrib/websocket v1.3.2/go.mod h1:07u6QGMsvX+sx7iGNCl5xhzuUVArWwLQ3tBIH24i+S8=
github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo=
github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
Expand Down Expand Up @@ -385,6 +389,8 @@ github.com/sashamelentyev/interfacebloat v1.1.0 h1:xdRdJp0irL086OyW1H/RTZTr1h/tM
github.com/sashamelentyev/interfacebloat v1.1.0/go.mod h1:+Y9yU5YdTkrNvoX0xHc84dxiN1iBi9+G8zZIhPVoNjQ=
github.com/sashamelentyev/usestdlibvars v1.27.0 h1:t/3jZpSXtRPRf2xr0m63i32ZrusyurIGT9E5wAvXQnI=
github.com/sashamelentyev/usestdlibvars v1.27.0/go.mod h1:9nl0jgOfHKWNFS43Ojw0i7aRoS4j6EBye3YBhmAIRF8=
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511 h1:KanIMPX0QdEdB4R3CiimCAbxFrhB3j7h0/OvpYGVQa8=
github.com/savsgio/gotils v0.0.0-20240303185622-093b76447511/go.mod h1:sM7Mt7uEoCeFSCBM+qBrqvEo+/9vdmj19wzp3yzUhmg=
github.com/securego/gosec/v2 v2.20.1-0.20240822074752-ab3f6c1c83a0 h1:VqD4JMoqwuuCz8GZlBDsIDyE6K4YUsWJpbNtuOWHoFk=
github.com/securego/gosec/v2 v2.20.1-0.20240822074752-ab3f6c1c83a0/go.mod h1:iyeMMRw8QEmueUSZ2VqmkQMiDyDcobfPnG00CV/NWdE=
github.com/shazow/go-diff v0.0.0-20160112020656-b6b7b6733b8c h1:W65qqJCIOVP4jpqPQ0YvHYKwcMEMVWIzWC5iNQQfBTU=
Expand Down Expand Up @@ -488,8 +494,12 @@ github.com/zeiss/fiber-authz v1.0.33 h1:KZnVTxG+VoQLowoCqoMwam/5H4PVu89rn9ZJ2AGO
github.com/zeiss/fiber-authz v1.0.33/go.mod h1:oVkhY0X9/xFa0Pu3BuEU8ubE7pAQmIjFMUwUGD2pQqc=
github.com/zeiss/fiber-goth v1.2.11 h1:24EiIKF1iPrmlspbW/BylcqVyj4Ltwzmx9DM7pRs6R4=
github.com/zeiss/fiber-goth v1.2.11/go.mod h1:9NuXxIeKZgmk3dfl7HWbZK/eAfukvjMCHHacGo0m84Y=
github.com/zeiss/fiber-reload v0.1.0 h1:iiZzbHj2EntILhbF74HRZPDSLrvURmwTbUqGlKfo0h4=
github.com/zeiss/fiber-reload v0.1.0/go.mod h1:eUvohuk2nDjGCUtejTW5db5M28FZNJDtVEAZDZwq0Rg=
github.com/zeiss/pkg v0.1.8-0.20240820122414-ce95f079ee32 h1:cycuVXit5Emm5+tX5zwbgJrmlMHqfkI0u5UIs4LmJng=
github.com/zeiss/pkg v0.1.8-0.20240820122414-ce95f079ee32/go.mod h1:MDEraF5xLbffG1zSfbrFWIP8bGFyvQMlvRG/xgJKozE=
github.com/zeiss/pkg v0.1.8-0.20240823051228-d40ebe6703e0 h1:XeYJSeE7wHJ5JtnZZR2UD4Cf5HQljUuM2Bb5RloQQMs=
github.com/zeiss/pkg v0.1.8-0.20240823051228-d40ebe6703e0/go.mod h1:+oCr9cBeG3Eq37zzzPET8z2REQoA5C29+agQfLX5KZk=
gitlab.com/bosi/decorder v0.4.2 h1:qbQaV3zgwnBZ4zPMhGLW4KZe7A7NwxEhJx39R3shffo=
gitlab.com/bosi/decorder v0.4.2/go.mod h1:muuhHoaJkA9QLcYHq4Mj8FJUwDZ+EirSHRiaTcTf6T8=
go-simpler.org/assert v0.9.0 h1:PfpmcSvL7yAnWyChSjOz6Sp6m9j5lyK8Ok9pEL31YkQ=
Expand Down

0 comments on commit e7dd1e8

Please sign in to comment.