Controllers/Session

// init/app.go
package appinit

import (
	"os"

	"golazy.dev/lazyapp"
	"golazy.dev/lazysession"
	"sample_app/app"
)

func App() *lazyapp.App {
	return lazyapp.New(lazyapp.Config{
		Name:         "sample_app",
		Drawer:       Draw,
		Public:       app.Public,
		Views:        app.Views,
		Dependencies: Dependencies,
		Sessions: lazysession.Config{
			Key: os.Getenv("SESSION_KEY"),
		},
	})
}
// app/controllers/session_controller/sessioncontroller.go
package sessioncontroller

import (
	"net/http"

	"golazy.dev/lazycontroller"
)

func (c *SessionsController) Create(form *PasswordForm) error {
	if err := c.SessionSet("user_id", form.Username); err != nil {
		return err
	}
	if err := c.FlashSet("notice", "Signed in"); err != nil {
		return err
	}
	return c.RedirectToRoute("home", lazycontroller.RedirectStatus(http.StatusSeeOther))
}

func (c *SessionsController) Delete() error {
	if err := c.SessionDelete("user_id"); err != nil {
		return err
	}
	return c.RedirectToRoute("home", lazycontroller.RedirectStatus(http.StatusSeeOther))
}