Documentation ¶
Index ¶
- Constants
- Variables
- func AuthByCookie(handlerFunc echo.HandlerFunc) echo.HandlerFunc
- func Dashboard(ctx *AdminContext) error
- func HTMLError(e error, ctx echo.Context)
- func JSONError(e error, ctx echo.Context)
- func Login(ctx *AdminContext) error
- func Logout(ctx *AdminContext) error
- func Path(paths ...string) string
- func UserCreate(ctx *AdminContext) error
- func UserDelete(ctx *AdminContext) error
- func UserList(ctx *AdminContext) error
- func UserUpdate(ctx *AdminContext) error
- func WrapHandler(handleFunc AdminHandler) echo.HandlerFunc
- type Admin
- type AdminContext
- type AdminHandler
- type Asset
- type Config
- type DBConfig
- type Data
- type Renderer
- type Response
- type Token
- type TokenRepository
- type TokenType
- type User
- type UserFilter
- type UserRepository
- type UserRole
- type UserStatus
- type UserUseCase
- type ViewData
Constants ¶
View Source
const ( DefaultAssetsPath = "./assets" DefaultViewsPath = "./views" DefaultLimit = 20 Version = "v0.0.8" 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 ( DashboardURL = "/" LoginURL = "/login" LogoutURL = "/logout" UserListURL = "/users" UserCreateURL = "/users/create" UserUpdateURL = "/users/:id/update" UserDeleteURL = "/users/:id/delete" AccessCookieName = "auth_token" MigrationsTable = "goadmin_migrations" )
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") )
View Source
var ( JS = []Asset{ { "plugins/jquery/jquery-3.4.1.min.js", "https://code.jquery.com/jquery-3.4.1.min.js", -1000, }, { "plugins/popper/popper.min.js", "https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js", -900, }, { "plugins/bootstrap/js/bootstrap.min.js", "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js", -800, }, } CSS = []Asset{ { "plugins/bootstrap/css/bootstrap.min.css", "https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css", -1000, }, { "css/style.css", "https://raw.githubusercontent.com/partyzanex/go-admin-bootstrap/" + Version + "/assets/css/style.css", -900, }, } )
Functions ¶
func AuthByCookie ¶
func AuthByCookie(handlerFunc echo.HandlerFunc) echo.HandlerFunc
func Dashboard ¶
func Dashboard(ctx *AdminContext) error
func Login ¶
func Login(ctx *AdminContext) error
func Logout ¶
func Logout(ctx *AdminContext) error
func UserCreate ¶ added in v0.0.2
func UserCreate(ctx *AdminContext) error
func UserDelete ¶ added in v0.0.2
func UserDelete(ctx *AdminContext) error
func UserList ¶ added in v0.0.2
func UserList(ctx *AdminContext) error
func UserUpdate ¶ added in v0.0.2
func UserUpdate(ctx *AdminContext) error
func WrapHandler ¶
func WrapHandler(handleFunc AdminHandler) echo.HandlerFunc
Types ¶
type Admin ¶
type Admin struct { *Config // contains filtered or unexported fields }
func (*Admin) LoadSources ¶ added in v0.0.2
type AdminContext ¶
type AdminContext struct { echo.Context // contains filtered or unexported fields }
func (*AdminContext) Ctx ¶
func (c *AdminContext) Ctx() context.Context
func (*AdminContext) Data ¶
func (c *AdminContext) Data() *Data
func (AdminContext) URL ¶
func (c AdminContext) URL(path string) string
func (*AdminContext) User ¶
func (c *AdminContext) User() *User
func (*AdminContext) UserCase ¶
func (c *AdminContext) UserCase() UserUseCase
type AdminHandler ¶
type AdminHandler func(ctx *AdminContext) error
type Config ¶
type Token ¶
type TokenRepository ¶
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:"-"` }
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) Delete(ctx context.Context, user User) error }
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 }
Source Files ¶
Click to show internal directories.
Click to hide internal directories.