goadmin

package module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 18, 2024 License: MIT Imports: 22 Imported by: 0

README

go-admin-bootstrap

go get -u github.com/partyzanex/go-admin-bootstrap/cmd/goadmin-users

Documentation

Index

Constants

View Source
const (
	DefaultAssetsPath = "./assets"
	DefaultViewsPath  = "./views"
	DefaultLimit      = 20

	UserContextKey = "goadmin_user"
	DataContextKey = "goadmin_data"

	AuthToken TokenType = "auth"

	UserNew     UserStatus = "new"
	UserActive  UserStatus = "active"
	UserBlocked UserStatus = "blocked"

	RoleOwner UserRole = "owner"
	RoleRoot  UserRole = "root"
	RoleUser  UserRole = "user"
)

Variables

View Source
var (
	JS = []*Asset{
		{"plugins/jquery/jquery-3.4.1.min.js", -1000, JavaScript},
		{"plugins/popper/popper.min.js", -900, JavaScript},
		{"plugins/bootstrap/js/bootstrap.min.js", -800, JavaScript},
	}
	CSS = []*Asset{
		{"plugins/bootstrap/css/bootstrap.min.css", -1000, Stylesheet},
		{"css/style.css", -900, Stylesheet},
	}
	Views = []*Asset{
		{"layouts/nav.jet", 0, View},
		{"layouts/main.jet", 0, View},
		{"widgets/breadcrumbs.jet", 0, View},
		{"widgets/pagination.jet", 0, View},
		{"index/dashboard.jet", 0, View},
		{"errors/error.jet", 0, View},
		{"auth/login.jet", 0, View},
		{"user/form.jet", 0, View},
		{"user/index.jet", 0, View},
	}
)
View Source
var (
	DashboardURL = "/"
	LoginURL     = "/login"
	LogoutURL    = "/logout"

	UserListURL   = "/users"
	UserCreateURL = "/users/create"
	UserUpdateURL = "/users/:id/update"
	UserDeleteURL = "/users/:id/delete"

	AccessCookieName = "auth_token"
	MigrationsTable  = "goadmin_migrations"

	FaviconPrefix = "/favicon/:id"
)
View Source
var (
	ErrInvalidPort          = errors.New("invalid http port")
	ErrRequiredDB           = errors.New("required database connection instance")
	ErrContextNotConfigured = errors.New("admin context not configured")
	ErrRequiredUserName     = errors.New("required user name")
	ErrRequiredUserLogin    = errors.New("required user login")
	ErrInvalidUserLogin     = errors.New("invalid user login")
	ErrInvalidUserStatus    = errors.New("invalid user status")
	ErrRequiredUserID       = errors.New("required user id")
	ErrRequiredUserPassword = errors.New("required user password")
	ErrWrongPassword        = errors.New("wrong password")
	ErrUserNotFound         = errors.New("user not found")
	ErrInvalidUserRole      = errors.New("invalid user role")
	ErrTokenNotFound        = errors.New("token not found")
	ErrTokenExpired         = errors.New("token expired")
	ErrRequiredConfig       = errors.New("required config")
)

Functions

func AuthByCookie

func AuthByCookie(handlerFunc echo.HandlerFunc) echo.HandlerFunc

func Dashboard

func Dashboard(ctx *AppContext) error

func Favicon added in v0.2.0

func Favicon(ctx echo.Context) error

func HTMLError

func HTMLError(e error, ctx echo.Context)

func HTTPError added in v0.2.0

func HTTPError(e error, ctx echo.Context)

func JSONError

func JSONError(e error, ctx echo.Context)

func Login

func Login(ctx *AppContext) error

func Logout

func Logout(ctx *AppContext) error

func Path

func Path(paths ...string) string

func UserCreate added in v0.0.2

func UserCreate(ctx *AppContext) error

func UserDelete added in v0.0.2

func UserDelete(ctx *AppContext) error

func UserList added in v0.0.2

func UserList(ctx *AppContext) error

func UserUpdate added in v0.0.2

func UserUpdate(ctx *AppContext) error

func WrapHandler

func WrapHandler(handleFunc AdminHandler) echo.HandlerFunc

Types

type AdminHandler

type AdminHandler func(ctx *AppContext) error

type App added in v0.2.0

type App struct {
	// contains filtered or unexported fields
}

func New

func New(config *Config) (*App, error)

func (*App) Admin added in v0.2.0

func (app *App) Admin() *echo.Group

func (*App) Close added in v0.3.0

func (app *App) Close() error

func (*App) CreateAssets added in v0.2.0

func (app *App) CreateAssets() error

func (*App) Echo added in v0.2.0

func (app *App) Echo() *echo.Echo

func (*App) Serve added in v0.2.0

func (app *App) Serve() error

func (*App) Static added in v0.2.0

func (app *App) Static() *echo.Group

type AppContext added in v0.2.0

type AppContext struct {
	echo.Context
	// contains filtered or unexported fields
}

func (*AppContext) Ctx added in v0.2.0

func (c *AppContext) Ctx() context.Context

func (*AppContext) Data added in v0.2.0

func (c *AppContext) Data() *Data

func (*AppContext) URL added in v0.2.0

func (c *AppContext) URL(path string, args ...interface{}) string

func (*AppContext) User added in v0.2.0

func (c *AppContext) User() *User

func (*AppContext) UserCase added in v0.2.0

func (c *AppContext) UserCase() UserUseCase

type Asset added in v0.0.2

type Asset struct {
	Path      string
	SortOrder int
	Kind      AssetKind
}

type AssetKind added in v0.2.0

type AssetKind uint8
const (
	JavaScript AssetKind = iota
	Stylesheet
	View
)

type Config

type Config struct {
	Host string
	Port uint16

	BaseURL    string
	ViewsPath  string
	AssetsPath string

	DevMode bool

	DBConfig DBConfig
	UserCase UserUseCase

	Middleware []echo.MiddlewareFunc
	Assets     []*Asset
}

func (*Config) Clone added in v0.2.0

func (config *Config) Clone() *Config

func (*Config) Validate

func (config *Config) Validate() error

type DBConfig

type DBConfig struct {
	DB              *sql.DB
	MigrationsTable string
}

type Data

type Data struct {
	jet.VarMap

	Title       string
	User        *User
	Breadcrumbs widgets.Breadcrumbs
}

func (Data) Has added in v0.0.9

func (data Data) Has(key string) bool

func (*Data) JetData

func (data *Data) JetData() map[string]interface{}

func (*Data) JetVars

func (data *Data) JetVars() jet.VarMap

func (*Data) Set

func (data *Data) Set(name string, value interface{})

type FSLoader added in v0.3.0

type FSLoader struct {
	// contains filtered or unexported fields
}

func NewFSLoader added in v0.3.0

func NewFSLoader(fs *embed.FS) *FSLoader

func (*FSLoader) Exists added in v0.3.0

func (l *FSLoader) Exists(templatePath string) bool

func (*FSLoader) Open added in v0.3.0

func (l *FSLoader) Open(templatePath string) (io.ReadCloser, error)

type Renderer

type Renderer struct {
	Views *jet.Set
}

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, name string, data interface{}, _ echo.Context) error

type Response

type Response struct {
	Success bool        `json:"success"`
	Error   string      `json:"error,omitempty"`
	Data    interface{} `json:"data,omitempty"`
}

type Token

type Token struct {
	UserID    int64     `db:"user_id" json:"user_id"`
	Token     string    `db:"token" json:"token"`
	Type      TokenType `db:"type" json:"type"`
	DTExpired time.Time `db:"dt_expired" json:"dt_expired"`
	DTCreated time.Time `db:"dt_created" json:"dt_created"`

	User *User `db:"-"`
}

func (*Token) IsExpired

func (t *Token) IsExpired() bool

type TokenRepository

type TokenRepository interface {
	Search(ctx context.Context, token string) (*Token, error)
	Create(ctx context.Context, token *Token) (*Token, error)
}

type TokenType

type TokenType string

func (TokenType) IsValid

func (t TokenType) IsValid() bool

type User

type User struct {
	ID int64 `db:"id" json:"id"`

	Login    string     `db:"login" json:"login"`
	Password string     `db:"password" json:"password"`
	Status   UserStatus `db:"status" json:"status"`
	Name     string     `db:"name" json:"name"`
	Role     UserRole   `db:"role" json:"role"`

	DTCreated    time.Time `db:"dt_created" json:"dt_created"`
	DTUpdated    time.Time `db:"dt_updated" json:"dt_updated"`
	DTLastLogged time.Time `db:"dt_last_logged" json:"dt_last_logged"`

	PasswordIsEncoded bool `db:"password_is_encoded" json:"-"`
	Current           bool `db:"-" json:"-"`
}

func (*User) GetDTCreated added in v0.3.0

func (user *User) GetDTCreated() string

func (*User) GetDTLastLogged added in v0.3.0

func (user *User) GetDTLastLogged() string

func (*User) GetDTUpdated added in v0.3.0

func (user *User) GetDTUpdated() string

type UserFilter

type UserFilter struct {
	IDs           []int64
	Name          string
	Login         string
	Status        UserStatus
	Limit, Offset int
}

type UserRepository

type UserRepository interface {
	Search(ctx context.Context, filter *UserFilter) ([]*User, error)
	Count(ctx context.Context, filter *UserFilter) (int64, error)
	Create(ctx context.Context, user *User) (*User, error)
	Update(ctx context.Context, user *User) (*User, error)
	SetLastLogged(ctx context.Context, user *User) error
	Delete(ctx context.Context, user *User) error
}

type UserRole added in v0.0.2

type UserRole string

func (UserRole) IsValid added in v0.0.2

func (role UserRole) IsValid() bool

type UserStatus

type UserStatus string

func (UserStatus) IsValid

func (status UserStatus) IsValid() bool

type UserUseCase

type UserUseCase interface {
	Validate(user *User, create bool) error

	SearchByLogin(ctx context.Context, login string) (*User, error)
	SearchByID(ctx context.Context, id int64) (*User, error)
	SetLastLogged(ctx context.Context, user *User) error
	Register(ctx context.Context, user *User) error

	ComparePassword(user *User, password string) (bool, error)
	EncodePassword(user *User) error

	CreateAuthToken(ctx context.Context, user *User) (*Token, error)
	SearchToken(ctx context.Context, token string) (*Token, error)

	UserRepository() UserRepository
}

type ViewData

type ViewData interface {
	JetVars() jet.VarMap
	JetData() map[string]interface{}
}

Directories

Path Synopsis
cmd
db
pkg
cmd
repository

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL