Lint check adjustments.
This commit is contained in:
parent
944a4d941a
commit
51e44a57a1
18 changed files with 120 additions and 92 deletions
|
|
@ -9,23 +9,23 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
About struct {
|
||||
about struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
AboutData struct {
|
||||
aboutData struct {
|
||||
ShowCacheWarning bool
|
||||
FrontendTabs []AboutTab
|
||||
BackendTabs []AboutTab
|
||||
FrontendTabs []aboutTab
|
||||
BackendTabs []aboutTab
|
||||
}
|
||||
|
||||
AboutTab struct {
|
||||
aboutTab struct {
|
||||
Title string
|
||||
Body template.HTML
|
||||
}
|
||||
)
|
||||
|
||||
func (c *About) Get(ctx echo.Context) error {
|
||||
func (c *about) Get(ctx echo.Context) error {
|
||||
page := controller.NewPage(ctx)
|
||||
page.Layout = "main"
|
||||
page.Name = "about"
|
||||
|
|
@ -37,9 +37,9 @@ func (c *About) Get(ctx echo.Context) error {
|
|||
|
||||
// A simple example of how the Data field can contain anything you want to send to the templates
|
||||
// even though you wouldn't normally send markup like this
|
||||
page.Data = AboutData{
|
||||
page.Data = aboutData{
|
||||
ShowCacheWarning: true,
|
||||
FrontendTabs: []AboutTab{
|
||||
FrontendTabs: []aboutTab{
|
||||
{
|
||||
Title: "HTMX",
|
||||
Body: template.HTML(`Completes HTML as a hypertext by providing attributes to AJAXify anything and much more. Visit <a href="https://htmx.org/">htmx.org</a> to learn more.`),
|
||||
|
|
@ -53,7 +53,7 @@ func (c *About) Get(ctx echo.Context) error {
|
|||
Body: template.HTML(`Ready-to-use frontend components that you can easily combine to build responsive web interfaces with no JavaScript requirements. Visit <a href="https://bulma.io/">bulma.io</a> to learn more.`),
|
||||
},
|
||||
},
|
||||
BackendTabs: []AboutTab{
|
||||
BackendTabs: []aboutTab{
|
||||
{
|
||||
Title: "Echo",
|
||||
Body: template.HTML(`High performance, extensible, minimalist Go web framework. Visit <a href="https://echo.labstack.com/">echo.labstack.com</a> to learn more.`),
|
||||
|
|
|
|||
|
|
@ -10,33 +10,33 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
Contact struct {
|
||||
contact struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
ContactForm struct {
|
||||
contactForm struct {
|
||||
Email string `form:"email" validate:"required,email"`
|
||||
Message string `form:"message" validate:"required"`
|
||||
Submission controller.FormSubmission
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Contact) Get(ctx echo.Context) error {
|
||||
func (c *contact) Get(ctx echo.Context) error {
|
||||
page := controller.NewPage(ctx)
|
||||
page.Layout = "main"
|
||||
page.Name = "contact"
|
||||
page.Title = "Contact us"
|
||||
page.Form = ContactForm{}
|
||||
page.Form = contactForm{}
|
||||
|
||||
if form := ctx.Get(context.FormKey); form != nil {
|
||||
page.Form = form.(*ContactForm)
|
||||
page.Form = form.(*contactForm)
|
||||
}
|
||||
|
||||
return c.RenderPage(ctx, page)
|
||||
}
|
||||
|
||||
func (c *Contact) Post(ctx echo.Context) error {
|
||||
var form ContactForm
|
||||
func (c *contact) Post(ctx echo.Context) error {
|
||||
var form contactForm
|
||||
ctx.Set(context.FormKey, &form)
|
||||
|
||||
// Parse the form values
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ import (
|
|||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
type errorHandler struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
func (e *Error) Get(err error, ctx echo.Context) {
|
||||
func (e *errorHandler) Get(err error, ctx echo.Context) {
|
||||
if ctx.Response().Committed || context.IsCanceledError(err) {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,32 +14,32 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
ForgotPassword struct {
|
||||
forgotPassword struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
ForgotPasswordForm struct {
|
||||
forgotPasswordForm struct {
|
||||
Email string `form:"email" validate:"required,email"`
|
||||
Submission controller.FormSubmission
|
||||
}
|
||||
)
|
||||
|
||||
func (c *ForgotPassword) Get(ctx echo.Context) error {
|
||||
func (c *forgotPassword) Get(ctx echo.Context) error {
|
||||
page := controller.NewPage(ctx)
|
||||
page.Layout = "auth"
|
||||
page.Name = "forgot-password"
|
||||
page.Title = "Forgot password"
|
||||
page.Form = ForgotPasswordForm{}
|
||||
page.Form = forgotPasswordForm{}
|
||||
|
||||
if form := ctx.Get(context.FormKey); form != nil {
|
||||
page.Form = form.(*ForgotPasswordForm)
|
||||
page.Form = form.(*forgotPasswordForm)
|
||||
}
|
||||
|
||||
return c.RenderPage(ctx, page)
|
||||
}
|
||||
|
||||
func (c *ForgotPassword) Post(ctx echo.Context) error {
|
||||
var form ForgotPasswordForm
|
||||
func (c *forgotPassword) Post(ctx echo.Context) error {
|
||||
var form forgotPasswordForm
|
||||
ctx.Set(context.FormKey, &form)
|
||||
|
||||
succeed := func() error {
|
||||
|
|
|
|||
|
|
@ -9,17 +9,17 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
Home struct {
|
||||
home struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
Post struct {
|
||||
post struct {
|
||||
Title string
|
||||
Body string
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Home) Get(ctx echo.Context) error {
|
||||
func (c *home) Get(ctx echo.Context) error {
|
||||
page := controller.NewPage(ctx)
|
||||
page.Layout = "main"
|
||||
page.Name = "home"
|
||||
|
|
@ -32,12 +32,12 @@ func (c *Home) Get(ctx echo.Context) error {
|
|||
}
|
||||
|
||||
// fetchPosts is an mock example of fetching posts to illustrate how paging works
|
||||
func (c *Home) fetchPosts(pager *controller.Pager) []Post {
|
||||
func (c *home) fetchPosts(pager *controller.Pager) []post {
|
||||
pager.SetItems(20)
|
||||
posts := make([]Post, 20)
|
||||
posts := make([]post, 20)
|
||||
|
||||
for k := range posts {
|
||||
posts[k] = Post{
|
||||
posts[k] = post{
|
||||
Title: fmt.Sprintf("Post example #%d", k+1),
|
||||
Body: fmt.Sprintf("Lorem ipsum example #%d ddolor sit amet, consectetur adipiscing elit. Nam elementum vulputate tristique.", k+1),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,33 +14,33 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
Login struct {
|
||||
login struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
LoginForm struct {
|
||||
loginForm struct {
|
||||
Email string `form:"email" validate:"required,email"`
|
||||
Password string `form:"password" validate:"required"`
|
||||
Submission controller.FormSubmission
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Login) Get(ctx echo.Context) error {
|
||||
func (c *login) Get(ctx echo.Context) error {
|
||||
page := controller.NewPage(ctx)
|
||||
page.Layout = "auth"
|
||||
page.Name = "login"
|
||||
page.Title = "Log in"
|
||||
page.Form = LoginForm{}
|
||||
page.Form = loginForm{}
|
||||
|
||||
if form := ctx.Get(context.FormKey); form != nil {
|
||||
page.Form = form.(*LoginForm)
|
||||
page.Form = form.(*loginForm)
|
||||
}
|
||||
|
||||
return c.RenderPage(ctx, page)
|
||||
}
|
||||
|
||||
func (c *Login) Post(ctx echo.Context) error {
|
||||
var form LoginForm
|
||||
func (c *login) Post(ctx echo.Context) error {
|
||||
var form loginForm
|
||||
ctx.Set(context.FormKey, &form)
|
||||
|
||||
authFailed := func() error {
|
||||
|
|
|
|||
|
|
@ -7,11 +7,11 @@ import (
|
|||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
type Logout struct {
|
||||
type logout struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
func (l *Logout) Get(c echo.Context) error {
|
||||
func (l *logout) Get(c echo.Context) error {
|
||||
if err := l.Container.Auth.Logout(c); err == nil {
|
||||
msg.Success(c, "You have been logged out successfully.")
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -12,11 +12,11 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
Register struct {
|
||||
register struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
RegisterForm struct {
|
||||
registerForm struct {
|
||||
Name string `form:"name" validate:"required"`
|
||||
Email string `form:"email" validate:"required,email"`
|
||||
Password string `form:"password" validate:"required"`
|
||||
|
|
@ -25,22 +25,22 @@ type (
|
|||
}
|
||||
)
|
||||
|
||||
func (c *Register) Get(ctx echo.Context) error {
|
||||
func (c *register) Get(ctx echo.Context) error {
|
||||
page := controller.NewPage(ctx)
|
||||
page.Layout = "auth"
|
||||
page.Name = "register"
|
||||
page.Title = "Register"
|
||||
page.Form = RegisterForm{}
|
||||
page.Form = registerForm{}
|
||||
|
||||
if form := ctx.Get(context.FormKey); form != nil {
|
||||
page.Form = form.(*RegisterForm)
|
||||
page.Form = form.(*registerForm)
|
||||
}
|
||||
|
||||
return c.RenderPage(ctx, page)
|
||||
}
|
||||
|
||||
func (c *Register) Post(ctx echo.Context) error {
|
||||
var form RegisterForm
|
||||
func (c *register) Post(ctx echo.Context) error {
|
||||
var form registerForm
|
||||
ctx.Set(context.FormKey, &form)
|
||||
|
||||
// Parse the form values
|
||||
|
|
@ -96,7 +96,7 @@ func (c *Register) Post(ctx echo.Context) error {
|
|||
return c.Redirect(ctx, "home")
|
||||
}
|
||||
|
||||
func (c *Register) sendVerificationEmail(ctx echo.Context, usr *ent.User) {
|
||||
func (c *register) sendVerificationEmail(ctx echo.Context, usr *ent.User) {
|
||||
// Generate a token
|
||||
token, err := c.Container.Auth.GenerateEmailVerificationToken(usr.Email)
|
||||
if err != nil {
|
||||
|
|
|
|||
|
|
@ -10,33 +10,33 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
ResetPassword struct {
|
||||
resetPassword struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
ResetPasswordForm struct {
|
||||
resetPasswordForm struct {
|
||||
Password string `form:"password" validate:"required"`
|
||||
ConfirmPassword string `form:"password-confirm" validate:"required,eqfield=Password"`
|
||||
Submission controller.FormSubmission
|
||||
}
|
||||
)
|
||||
|
||||
func (c *ResetPassword) Get(ctx echo.Context) error {
|
||||
func (c *resetPassword) Get(ctx echo.Context) error {
|
||||
page := controller.NewPage(ctx)
|
||||
page.Layout = "auth"
|
||||
page.Name = "reset-password"
|
||||
page.Title = "Reset password"
|
||||
page.Form = ResetPasswordForm{}
|
||||
page.Form = resetPasswordForm{}
|
||||
|
||||
if form := ctx.Get(context.FormKey); form != nil {
|
||||
page.Form = form.(*ResetPasswordForm)
|
||||
page.Form = form.(*resetPasswordForm)
|
||||
}
|
||||
|
||||
return c.RenderPage(ctx, page)
|
||||
}
|
||||
|
||||
func (c *ResetPassword) Post(ctx echo.Context) error {
|
||||
var form ResetPasswordForm
|
||||
func (c *resetPassword) Post(ctx echo.Context) error {
|
||||
var form resetPasswordForm
|
||||
ctx.Set(context.FormKey, &form)
|
||||
|
||||
// Parse the form values
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func BuildRouter(c *services.Container) {
|
|||
ctr := controller.NewController(c)
|
||||
|
||||
// Error handler
|
||||
err := Error{Controller: ctr}
|
||||
err := errorHandler{Controller: ctr}
|
||||
c.Web.HTTPErrorHandler = err.Get
|
||||
|
||||
// Example routes
|
||||
|
|
@ -65,37 +65,37 @@ func BuildRouter(c *services.Container) {
|
|||
}
|
||||
|
||||
func navRoutes(c *services.Container, g *echo.Group, ctr controller.Controller) {
|
||||
home := Home{Controller: ctr}
|
||||
home := home{Controller: ctr}
|
||||
g.GET("/", home.Get).Name = "home"
|
||||
|
||||
search := Search{Controller: ctr}
|
||||
search := search{Controller: ctr}
|
||||
g.GET("/search", search.Get).Name = "search"
|
||||
|
||||
about := About{Controller: ctr}
|
||||
about := about{Controller: ctr}
|
||||
g.GET("/about", about.Get).Name = "about"
|
||||
|
||||
contact := Contact{Controller: ctr}
|
||||
contact := contact{Controller: ctr}
|
||||
g.GET("/contact", contact.Get).Name = "contact"
|
||||
g.POST("/contact", contact.Post).Name = "contact.post"
|
||||
}
|
||||
|
||||
func userRoutes(c *services.Container, g *echo.Group, ctr controller.Controller) {
|
||||
logout := Logout{Controller: ctr}
|
||||
logout := logout{Controller: ctr}
|
||||
g.GET("/logout", logout.Get, middleware.RequireAuthentication()).Name = "logout"
|
||||
|
||||
verifyEmail := VerifyEmail{Controller: ctr}
|
||||
verifyEmail := verifyEmail{Controller: ctr}
|
||||
g.GET("/email/verify/:token", verifyEmail.Get).Name = "verify_email"
|
||||
|
||||
noAuth := g.Group("/user", middleware.RequireNoAuthentication())
|
||||
login := Login{Controller: ctr}
|
||||
login := login{Controller: ctr}
|
||||
noAuth.GET("/login", login.Get).Name = "login"
|
||||
noAuth.POST("/login", login.Post).Name = "login.post"
|
||||
|
||||
register := Register{Controller: ctr}
|
||||
register := register{Controller: ctr}
|
||||
noAuth.GET("/register", register.Get).Name = "register"
|
||||
noAuth.POST("/register", register.Post).Name = "register.post"
|
||||
|
||||
forgot := ForgotPassword{Controller: ctr}
|
||||
forgot := forgotPassword{Controller: ctr}
|
||||
noAuth.GET("/password", forgot.Get).Name = "forgot_password"
|
||||
noAuth.POST("/password", forgot.Post).Name = "forgot_password.post"
|
||||
|
||||
|
|
@ -103,7 +103,7 @@ func userRoutes(c *services.Container, g *echo.Group, ctr controller.Controller)
|
|||
middleware.LoadUser(c.ORM),
|
||||
middleware.LoadValidPasswordToken(c.Auth),
|
||||
)
|
||||
reset := ResetPassword{Controller: ctr}
|
||||
reset := resetPassword{Controller: ctr}
|
||||
resetGroup.GET("/token/:user/:password_token/:token", reset.Get).Name = "reset_password"
|
||||
resetGroup.POST("/token/:user/:password_token/:token", reset.Post).Name = "reset_password.post"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,29 +10,29 @@ import (
|
|||
)
|
||||
|
||||
type (
|
||||
Search struct {
|
||||
search struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
SearchResult struct {
|
||||
searchResult struct {
|
||||
Title string
|
||||
URL string
|
||||
}
|
||||
)
|
||||
|
||||
func (c *Search) Get(ctx echo.Context) error {
|
||||
func (c *search) Get(ctx echo.Context) error {
|
||||
page := controller.NewPage(ctx)
|
||||
page.Layout = "main"
|
||||
page.Name = "search"
|
||||
|
||||
// Fake search results
|
||||
var results []SearchResult
|
||||
var results []searchResult
|
||||
if search := ctx.QueryParam("query"); search != "" {
|
||||
for i := 0; i < 5; i++ {
|
||||
title := "Lorem ipsum example ddolor sit amet"
|
||||
index := rand.Intn(len(title))
|
||||
title = title[:index] + search + title[index:]
|
||||
results = append(results, SearchResult{
|
||||
results = append(results, searchResult{
|
||||
Title: title,
|
||||
URL: fmt.Sprintf("https://www.%s.com", search),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -9,11 +9,11 @@ import (
|
|||
"github.com/mikestefanello/pagoda/msg"
|
||||
)
|
||||
|
||||
type VerifyEmail struct {
|
||||
type verifyEmail struct {
|
||||
controller.Controller
|
||||
}
|
||||
|
||||
func (c *VerifyEmail) Get(ctx echo.Context) error {
|
||||
func (c *verifyEmail) Get(ctx echo.Context) error {
|
||||
var usr *ent.User
|
||||
|
||||
// Validate the token
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue