Skip to content

Commit

Permalink
feat: add session to ctrl
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie committed Jun 17, 2024
1 parent edde9f3 commit 7d05c1e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
12 changes: 12 additions & 0 deletions ctrl.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"errors"

"github.com/gofiber/fiber/v2"
goth "github.com/zeiss/fiber-goth"
"github.com/zeiss/fiber-goth/adapters"
"gorm.io/gorm"
)

Expand Down Expand Up @@ -167,6 +169,16 @@ func (c *DefaultController) ValuesBool(key any, value ...any) (val bool) {
return c.ctx.Locals(key, value...).(bool)
}

// Session is a helper function to get the session from the context.
func (c *DefaultController) Session() (adapters.GothSession, error) {
session, err := goth.SessionFromContext(c.Ctx())
if err != nil {
return adapters.GothSession{}, err
}

return session, nil
}

// Context returns the context.
func (c *DefaultController) Context() context.Context {
return c.ctx.Context()
Expand Down
7 changes: 4 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.21.9
go 1.22

toolchain go1.22.2
toolchain go1.22.3

require (
github.com/go-playground/validator/v10 v10.22.0
Expand All @@ -12,6 +12,7 @@ require (
github.com/katallaxie/pkg v0.6.5
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
github.com/zeiss/fiber-goth v1.2.4
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
gorm.io/gorm v1.25.10
mvdan.cc/gofumpt v0.6.0
Expand Down Expand Up @@ -181,7 +182,7 @@ require (
github.com/ultraware/whitespace v0.1.1 // indirect
github.com/uudashr/gocognit v1.1.2 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
github.com/valyala/fasthttp v1.53.0 // indirect
github.com/valyala/fasthttp v1.54.0 // indirect
github.com/valyala/tcplisten v1.0.0 // indirect
github.com/xen0n/gosmopolitan v1.2.2 // indirect
github.com/yagipy/maintidx v1.0.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -412,8 +412,8 @@ github.com/uudashr/gocognit v1.1.2 h1:l6BAEKJqQH2UpKAPKdMfZf5kE4W/2xk8pfU1OVLvni
github.com/uudashr/gocognit v1.1.2/go.mod h1:aAVdLURqcanke8h3vg35BC++eseDm66Z7KmchI5et4k=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasthttp v1.53.0 h1:lW/+SUkOxCx2vlIu0iaImv4JLrVRnbbkpCoaawvA4zc=
github.com/valyala/fasthttp v1.53.0/go.mod h1:6dt4/8olwq9QARP/TDuPmWyWcl4byhpvTJ4AAtcz+QM=
github.com/valyala/fasthttp v1.54.0 h1:cCL+ZZR3z3HPLMVfEYVUMtJqVaui0+gu7Lx63unHwS0=
github.com/valyala/fasthttp v1.54.0/go.mod h1:6dt4/8olwq9QARP/TDuPmWyWcl4byhpvTJ4AAtcz+QM=
github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8=
github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc=
github.com/xen0n/gosmopolitan v1.2.2 h1:/p2KTnMzwRexIW8GlKawsTWOxn7UHA+jCMF/V8HHtvU=
Expand All @@ -430,6 +430,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/zeiss/fiber-goth v1.2.4 h1:tzuS4iXhCC9elEzVNVKILB4fBMa+wkaSqe8kr6jLA4c=
github.com/zeiss/fiber-goth v1.2.4/go.mod h1:TkapFI+7LOvbb093zF8cP/CH2PcQJSBQWQZDzgGoygE=
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 7d05c1e

Please sign in to comment.