generated from golang-templates/seed
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve the godest framework prototype (#19)
* Move the components and theme-overrides import files to styles/shared * Use the new @sargassum-world/styles npm package for shared stylesheets * Move the @sargassum-world/styles dependency to devDependencies * Move reused sprinkles @sargassum-world/stimulated, remove TypeScript * Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Bump github.com/labstack/echo/v4 from 4.6.3 to 4.7.0 Bumps [github.com/labstack/echo/v4](https://github.com/labstack/echo) from 4.6.3 to 4.7.0. - [Release notes](https://github.com/labstack/echo/releases) - [Changelog](https://github.com/labstack/echo/blob/master/CHANGELOG.md) - [Commits](labstack/echo@v4.6.3...v4.7.0) --- updated-dependencies: - dependency-name: github.com/labstack/echo/v4 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]> * Bump github.com/goreleaser/goreleaser from 0.178.0 to 1.6.1 in /tools Bumps [github.com/goreleaser/goreleaser](https://github.com/goreleaser/goreleaser) from 0.178.0 to 1.6.1. - [Release notes](https://github.com/goreleaser/goreleaser/releases) - [Changelog](https://github.com/goreleaser/goreleaser/blob/main/.goreleaser.yaml) - [Commits](goreleaser/goreleaser@v0.178.0...v1.6.1) --- updated-dependencies: - dependency-name: github.com/goreleaser/goreleaser dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <[email protected]> * Refactor client initialization * Move session and authn clients into godest package for sharing * Reduce API surface of godest package * Use github.com/pkg/errors instead of fmt for errors * Avoid bare returns * Clobber invalid sessions instead of returning HTTP 500, but log it first * Remove session client from Handlers structs where possible * Upgrade golang.org/x/sys * Repair go.sum problems introduced by merging dependabot branches Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
- Loading branch information
1 parent
1d6d0a7
commit efa3cfd
Showing
118 changed files
with
1,627 additions
and
3,277 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package auth | ||
|
||
import ( | ||
"github.com/gorilla/sessions" | ||
"github.com/labstack/echo/v4" | ||
"github.com/pkg/errors" | ||
|
||
"github.com/sargassum-world/fluitans/pkg/godest" | ||
"github.com/sargassum-world/fluitans/pkg/godest/session" | ||
) | ||
|
||
type ( | ||
Handler func(c echo.Context, a Auth) error | ||
HandlerWithSession func(c echo.Context, a Auth, sess *sessions.Session) error | ||
) | ||
|
||
func Handle(h Handler, sc *session.Client) echo.HandlerFunc { | ||
return func(c echo.Context) error { | ||
a, sess, err := GetWithSession(c.Request(), sc, c.Logger()) | ||
// We don't expect the handler to write to the session, so we save it now | ||
if serr := sess.Save(c.Request(), c.Response()); serr != nil { | ||
return errors.Wrap(err, "couldn't save new session to replace invalid session") | ||
} | ||
if err != nil { | ||
return err | ||
} | ||
return h(c, a) | ||
} | ||
} | ||
|
||
func HandleWithSession(h HandlerWithSession, sc *session.Client) echo.HandlerFunc { | ||
return func(c echo.Context) error { | ||
a, sess, err := GetWithSession(c.Request(), sc, c.Logger()) | ||
if err != nil { | ||
return err | ||
} | ||
return h(c, a, sess) | ||
} | ||
} | ||
|
||
// Router is a routing adapter between echo.Handler and this package's Handler, by | ||
// automatically extracting auth data from the session of the request. | ||
type Router struct { | ||
er godest.EchoRouter | ||
sc *session.Client | ||
} | ||
|
||
func NewRouter(er godest.EchoRouter, sc *session.Client) Router { | ||
return Router{ | ||
er: er, | ||
sc: sc, | ||
} | ||
} | ||
|
||
func (r *Router) CONNECT(path string, h Handler, m ...echo.MiddlewareFunc) *echo.Route { | ||
return r.er.CONNECT(path, Handle(h, r.sc), m...) | ||
} | ||
|
||
func (r *Router) DELETE(path string, h Handler, m ...echo.MiddlewareFunc) *echo.Route { | ||
return r.er.DELETE(path, Handle(h, r.sc), m...) | ||
} | ||
|
||
func (r *Router) GET(path string, h Handler, m ...echo.MiddlewareFunc) *echo.Route { | ||
return r.er.GET(path, Handle(h, r.sc), m...) | ||
} | ||
|
||
func (r *Router) HEAD(path string, h Handler, m ...echo.MiddlewareFunc) *echo.Route { | ||
return r.er.HEAD(path, Handle(h, r.sc), m...) | ||
} | ||
|
||
func (r *Router) OPTIONS(path string, h Handler, m ...echo.MiddlewareFunc) *echo.Route { | ||
return r.er.OPTIONS(path, Handle(h, r.sc), m...) | ||
} | ||
|
||
func (r *Router) PATCH(path string, h Handler, m ...echo.MiddlewareFunc) *echo.Route { | ||
return r.er.PATCH(path, Handle(h, r.sc), m...) | ||
} | ||
|
||
func (r *Router) POST(path string, h Handler, m ...echo.MiddlewareFunc) *echo.Route { | ||
return r.er.POST(path, Handle(h, r.sc), m...) | ||
} | ||
|
||
func (r *Router) PUT(path string, h Handler, m ...echo.MiddlewareFunc) *echo.Route { | ||
return r.er.PUT(path, Handle(h, r.sc), m...) | ||
} | ||
|
||
func (r *Router) TRACE(path string, h Handler, m ...echo.MiddlewareFunc) *echo.Route { | ||
return r.er.TRACE(path, Handle(h, r.sc), m...) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.