Normal view

There are new articles available, click to refresh the page.
Before yesterdayMain stream

有没有简单可靠的将 alexedwards/scs 中的 LoadAndSave 用在 gin 中的方法?

By: shendaowu
7 October 2025 at 10:19
shendaowu: 不用 LoadAndSave 太繁琐了。

我找到了这个:
https://github.com/39george/scs_gin_adapter
不过因为 star 太少,还有看起来跟 scs 的 LoadAndSave 有点不一样,所以不敢用。scs 的 LoadAndSave 是在中间件中 commit 的,只有一次。scs_gin_adapter 是每次 get 和 put 都 commit ,不知道有没有什么副作用。

https://github.com/alexedwards/scs/blob/ab20b3feb5e9981c1f79cee8a97a289810134163/session.go#L137
https://github.com/39george/scs_gin_adapter/blob/ad226a38c0e58f51dd5b4f7b9e5c728b073de0a5/scs_gin_adapter.go#L23

问了几次 DeepSeek ,代码根本用不了。不想花时间了。

还有我试了这个: https://github.com/alexedwards/scs/issues/164 。不过我不确定这个方式 LoadAndSave 对比 Use 是不是在更外层。我试了一下成功了。我自己写了一个中间件,用 Use 加进去,然后成功读取到会话了。如果这个方法可行的话,我总感觉这个方法有点不伦不类,不够优雅,怕出岔子。
❌
❌