Skip to content

Commit 926ed16

Browse files
feat: persist sessions
1 parent 88b1293 commit 926ed16

File tree

6 files changed

+18
-4
lines changed

6 files changed

+18
-4
lines changed

config/config.go

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
type Config struct {
2020
DatabasePath string
21+
SessionsPath string
2122
AttachmentsDirectory string
2223
HTTPDisable bool
2324
HTTPAddress string
@@ -47,6 +48,7 @@ func Parse(raw Raw) (Config, error) {
4748
}
4849

4950
databasePath := path.Join(dataDirectory, "smtpbridge.db")
51+
sessionsPath := path.Join(dataDirectory, "sessions.db")
5052

5153
attachmentsDirectory := path.Join(dataDirectory, "attachments")
5254
if err := os.MkdirAll(attachmentsDirectory, 0755); err != nil {
@@ -140,6 +142,7 @@ func Parse(raw Raw) (Config, error) {
140142

141143
return Config{
142144
DatabasePath: databasePath,
145+
SessionsPath: sessionsPath,
143146
AttachmentsDirectory: attachmentsDirectory,
144147
HTTPDisable: raw.HTTP.Disable,
145148
HTTPAddress: raw.HTTP.Host + ":" + strconv.Itoa(raw.HTTP.Port),

go.mod

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require (
1010
github.com/emersion/go-sasl v0.0.0-20220912192320-0145f2c60ead
1111
github.com/emersion/go-smtp v0.16.0
1212
github.com/gofiber/fiber/v2 v2.48.0
13+
github.com/gofiber/storage/bbolt v1.3.5
1314
github.com/gofiber/template/html/v2 v2.0.4
1415
github.com/jaytaylor/html2text v0.0.0-20200412013138-3577fbdbcff7
1516
github.com/jhillyerd/enmime v1.0.0
@@ -49,6 +50,7 @@ require (
4950
github.com/valyala/tcplisten v1.0.0 // indirect
5051
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
5152
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
53+
go.etcd.io/bbolt v1.3.7 // indirect
5254
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
5355
golang.org/x/mod v0.8.0 // indirect
5456
golang.org/x/net v0.8.0 // indirect

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,8 @@ github.com/go-test/deep v1.0.7 h1:/VSMRlnY/JSyqxQUzQLKVMAskpY/NZKFA5j2P+0pP2M=
285285
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
286286
github.com/gofiber/fiber/v2 v2.48.0 h1:cRVMCb9aUJDsyHxGFLwz/sGzDggdailZZyptU9F9cU0=
287287
github.com/gofiber/fiber/v2 v2.48.0/go.mod h1:xqJgfqrc23FJuqGOW6DVgi3HyZEm2Mn9pRqUb2kHSX8=
288+
github.com/gofiber/storage/bbolt v1.3.5 h1:9ZDMTbeah5tfj3eX+hFu3F1AHiBO117ce3Gel7tkxlk=
289+
github.com/gofiber/storage/bbolt v1.3.5/go.mod h1:GibrOAQTFOzzzWWVCgq+V+gS8dUbaPeAMGI4FNZ32sI=
288290
github.com/gofiber/template v1.8.2 h1:PIv9s/7Uq6m+Fm2MDNd20pAFFKt5wWs7ZBd8iV9pWwk=
289291
github.com/gofiber/template v1.8.2/go.mod h1:bs/2n0pSNPOkRa5VJ8zTIvedcI/lEYxzV3+YPXdBvq8=
290292
github.com/gofiber/template/html/v2 v2.0.4 h1:exZDo23hrYRqxoX4vPkJj31yxXTmlFEu2aHd+XmJmLM=
@@ -637,6 +639,8 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
637639
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
638640
github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
639641
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
642+
go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ=
643+
go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw=
640644
go.etcd.io/etcd/api/v3 v3.5.5/go.mod h1:KFtNaxGDw4Yx/BA4iPPwevUTAuqcsPxzyX8PHydchN8=
641645
go.etcd.io/etcd/client/pkg/v3 v3.5.5/go.mod h1:ggrwbk069qxpKPq8/FKkQ3Xq9y39kbFR4LnKszpRXeQ=
642646
go.etcd.io/etcd/client/v2 v2.305.5/go.mod h1:zQjKllfqfBVyVStbt4FaosoX2iYd8fV/GRy/PbowgP4=

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func run(ctx context.Context, shutdown context.CancelFunc, cli config.CLI) <-cha
7575

7676
// HTTP
7777
if !cfg.HTTPDisable {
78-
http := http.New(app, shutdown, cfg.HTTPAddress, cfg.HTTPBodyLimit)
78+
http := http.New(app, shutdown, cfg.HTTPAddress, cfg.HTTPBodyLimit, cfg.SessionsPath)
7979
backgrounds = append(backgrounds, http)
8080
}
8181

web/http/http.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/gofiber/fiber/v2/middleware/logger"
1313
"github.com/gofiber/fiber/v2/middleware/recover"
1414
"github.com/gofiber/fiber/v2/middleware/session"
15+
"github.com/gofiber/storage/bbolt"
1516
"github.com/rs/zerolog/log"
1617
)
1718

@@ -21,8 +22,12 @@ type HTTP struct {
2122
address string
2223
}
2324

24-
func New(app core.App, shutdown context.CancelFunc, address string, bodyLimit int) HTTP {
25-
store := session.New()
25+
func New(app core.App, shutdown context.CancelFunc, address string, bodyLimit int, sessionsPath string) HTTP {
26+
store := session.New(session.Config{
27+
Storage: bbolt.New(bbolt.Config{
28+
Database: sessionsPath,
29+
}),
30+
})
2631

2732
// Fiber
2833
views := web.Engine()

web/views/partials/header.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</ul>
1111
<ul class=" block lg:hidden">
1212
<li class="p-0 flex flex-items-center h-full">
13-
<details role="list" dir="rtl" open>
13+
<details role="list" dir="rtl">
1414
<summary aria-haspopup="listbox" class="block pico-no-chevron">
1515
<div class=" i-ri-align-justify h-6 w-6" />
1616
</summary>

0 commit comments

Comments
 (0)