goadmin

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2019 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAssetsPath = "./assets"
)

Variables

View Source
var (
	DashboardURL     = "/"
	LoginURL         = "/login"
	LogoutURL        = "/logout"
	AccessCookieName = "auth_token"

	ErrContextNotConfigured = errors.New("admin context not configured")
)
View Source
var (
	ErrWrongPassword = errors.New("wrong password")
	ErrUserNotFound  = errors.New("user not found")
	ErrTokenNotFound = errors.New("token not found")
)
View Source
var (
	DataContextKey = "data_context"
)

Functions

func AuthByCookie

func AuthByCookie(handlerFunc echo.HandlerFunc) echo.HandlerFunc

func Dashboard

func Dashboard(ctx *AdminContext) error

func HTMLError

func HTMLError(e error, ctx echo.Context)

func JSONError

func JSONError(e error, ctx echo.Context)

func Login

func Login(ctx *AdminContext) error

func Logout

func Logout(ctx *AdminContext) error

func Path

func Path(paths ...string) string

func WrapHandler

func WrapHandler(h AdminHandler) echo.HandlerFunc

Types

type Admin

type Admin struct {
	*Config
	// contains filtered or unexported fields
}

func New

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

func (*Admin) Echo

func (admin *Admin) Echo() *echo.Echo

func (*Admin) LoadAssets

func (admin *Admin) LoadAssets() error

func (*Admin) Serve

func (admin *Admin) Serve() error

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 AssetSource

type AssetSource struct {
	Path string
	URL  string
}

type Config

type Config struct {
	Host       string
	Port       uint16
	Middleware []echo.MiddlewareFunc
	BaseURL    string
	ViewsPath  string
	DevMode    bool
	AssetsPath string
	DBConfig   DBConfig
	// contains filtered or unexported fields
}

func (*Config) Validate

func (config *Config) Validate() error

type DBConfig

type DBConfig struct {
	DB         *sql.DB
	DBInstance database.Driver

	DriverName     string
	DatabaseName   string
	MigrationsPath string
}

type Data

type Data struct {
	jet.VarMap

	Title       string
	User        *User
	Breadcrumbs widgets.Breadcrumbs
}

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 Renderer

type Renderer struct {
	Views *jet.Set
}

func (*Renderer) Render

func (r *Renderer) Render(w io.Writer, name string, data interface{}, ctx 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) error
}

type TokenType

type TokenType string
const (
	AuthToken TokenType = "auth"
)

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"`

	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 {
	Name          string
	Login         string
	Status        UserStatus
	Limit, Offset int
}

type UserRepository

type UserRepository interface {
	Search(ctx context.Context, filter *UserFilter) ([]*User, 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
const (
	UserNew     UserStatus = "new"
	UserActive  UserStatus = "active"
	UserBlocked UserStatus = "blocked"

	UserContextKey = "user_context"
)

func (UserStatus) IsValid

func (status UserStatus) IsValid() bool

type UserUseCase

type UserUseCase interface {
	SearchByLogin(ctx context.Context, login string) (*User, error)
	ComparePassword(user *User, password string) (bool, error)
	CreateAuthToken(ctx context.Context, user *User) (*Token, error)
	SetLastLogged(ctx context.Context, user *User) error
	SearchToken(ctx context.Context, token string) (*Token, error)
}

type ViewData

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

Directories

Path Synopsis
db

Jump to

Keyboard shortcuts

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