Version: v0.0.2 Latest Latest

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

Go to latest
Published: Jun 23, 2016 License: MIT Imports: 35 Imported by: 0




This section is empty.


This section is empty.


func Secret

func Secret(i, l int) []byte

Secret get key from secret config

func SendMail

func SendMail(to, subject, body string, html bool, files ...string)

SendMail add mail job to queue

func Shell

func Shell(cmd string, args ...string) error

Shell run shell command


type AesHmacEncryptor

type AesHmacEncryptor struct {
	Cipher cipher.Block
	Hash   hash.Hash

AesHmacEncryptor using hmac and aes

func (*AesHmacEncryptor) Decode

func (p *AesHmacEncryptor) Decode(buf []byte) ([]byte, error)

Decode decode by aes

func (*AesHmacEncryptor) Encode

func (p *AesHmacEncryptor) Encode(buf []byte) ([]byte, error)

Encode encode by aes

func (*AesHmacEncryptor) Equal

func (p *AesHmacEncryptor) Equal(plain, code []byte) bool

Equal check hmac

func (*AesHmacEncryptor) Sum

func (p *AesHmacEncryptor) Sum(buf []byte) []byte

Sum sum by hmac

type Dao

type Dao struct {
	Db        *gorm.DB        `inject:""`
	Encryptor Encryptor       `inject:""`
	Logger    *logging.Logger `inject:""`

Dao db helper

func (*Dao) AddUser

func (p *Dao) AddUser(pid, pty, email, name, home, logo string) (*User, error)

AddUser add openid user

func (*Dao) Allow

func (p *Dao) Allow(role uint, user uint, years, months, days int) error

Allow allow permission

func (*Dao) Authority

func (p *Dao) Authority(user uint, rty string, rid uint) []string

Authority get user's role names

func (*Dao) Can

func (p *Dao) Can(user uint, name string, rty string, rid uint) bool

Can can?

func (*Dao) Deny

func (p *Dao) Deny(role uint, user uint) error

Deny deny permission

func (*Dao) Get

func (p *Dao) Get(k string, v interface{}) error

Get get setting value by key

func (*Dao) GetUser

func (p *Dao) GetUser(uid string) (*User, error)

GetUser get user by uid

func (*Dao) Is

func (p *Dao) Is(user uint, name string) bool

Is is role ?

func (*Dao) Log

func (p *Dao) Log(user uint, msg string)

Log add log

func (*Dao) Role

func (p *Dao) Role(name string, rty string, rid uint) (*Role, error)

Role check role exist

func (*Dao) Set

func (p *Dao) Set(k string, v interface{}, f bool) error

Set save setting

func (*Dao) UserClaims

func (p *Dao) UserClaims(u *User) jws.Claims

UserClaims generate user claims

type Encryptor

type Encryptor interface {
	Encode(buf []byte) ([]byte, error)
	Decode(buf []byte) ([]byte, error)
	Sum(buf []byte) []byte
	Equal(plain, code []byte) bool

Encryptor for encrypt and decrypt

func NewAesHmacEncryptor

func NewAesHmacEncryptor(ck, hk []byte) (Encryptor, error)

NewAesHmacEncryptor new AesHmacEncryptor

type Engine

type Engine struct {
	I18n              *i18n.I18n      `inject:""`
	Dao               *Dao            `inject:""`
	Jwt               *Jwt            `inject:""`
	Logger            *logging.Logger `inject:""`
	Cache             *web.Cache      `inject:""`
	Oauth2GoogleState string          `inject:""`

Engine platform engine

func (*Engine) Map

func (p *Engine) Map(inj *inject.Graph) error

Map map objects

func (*Engine) Migrate

func (p *Engine) Migrate(db *gorm.DB)

Migrate db:migrate

func (*Engine) Mount

func (p *Engine) Mount(r *gin.Engine)

Mount mount routes

func (*Engine) Seed

func (p *Engine) Seed()

Seed db:seed

func (*Engine) Shell

func (p *Engine) Shell() []cli.Command

Shell shell commands

func (*Engine) Worker

func (p *Engine) Worker()

Worker worker job

type GoogleCredential

type GoogleCredential struct {
	Web struct {
		ClientID     string   `json:"client_id"`
		ClientSecret string   `json:"client_secret"`
		RedirectURLS []string `json:"redirect_uris"`
	} `json:"web"`

GoogleCredential google creadential

func (*GoogleCredential) To

func (p *GoogleCredential) To() oauth2.Config

To to oauth2 config model

type GoogleUser

type GoogleUser struct {
	ID      string `json:"id"`
	Email   string `json:"email"`
	Name    string `json:"name"`
	Link    string `json:"link"`
	Picture string `json:"picture"`

GoogleUser google oauth user info

type Jwt

type Jwt struct {
	Key    []byte               `inject:"jwt.key"`
	Method crypto.SigningMethod `inject:"jwt.method"`
	Logger *logging.Logger      `inject:""`
	Redis  *redis.Pool          `inject:""`
	Dao    *Dao                 `inject:""`

Jwt jwt helper

func (*Jwt) CurrentUserHandler

func (p *Jwt) CurrentUserHandler(must bool) gin.HandlerFunc

CurrentUserHandler inject current user

func (*Jwt) MustAdminHandler

func (p *Jwt) MustAdminHandler() gin.HandlerFunc

MustAdminHandler check must have admin role

func (*Jwt) MustRolesHandler

func (p *Jwt) MustRolesHandler(roles ...string) gin.HandlerFunc

MustRolesHandler check must have one roles at least

func (*Jwt) Sum

func (p *Jwt) Sum(cm jws.Claims, days int) ([]byte, error)

Sum create jwt token

func (*Jwt) Validate

func (p *Jwt) Validate(buf []byte) (jwt.Claims, error)

Validate check jwt

type Log

type Log struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	UserID    uint      `gorm:"not null" json:"-"`
	User      User      `json:"-"`
	Message   string    `gorm:"not null;type:VARCHAR(255)" json:"message"`
	CreatedAt time.Time `gorm:"not null;default:current_timestamp" json:"created_at"`

Log model

type Notice

type Notice struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	Lang      string    `gorm:"not null;type:varchar(8);index" json:"lang"`
	Content   string    `gorm:"not null;type:text" json:"content"`
	CreatedAt time.Time `gorm:"not null;default:current_timestamp" json:"created_at"`

Notice notice model

type NoticeFm

type NoticeFm struct {
	Content string `form:"content" binding:"required"`

NoticeFm form for notice

type OauthFm

type OauthFm struct {
	Code  string `form:"code"`
	State string `form:"state"`

OauthFm oauth2 model

type Permission

type Permission struct {
	User   User
	UserID uint `gorm:"not null"`
	Role   Role
	RoleID uint      `gorm:"not null"`
	Begin  time.Time `gorm:"not null;default:current_date;type:date"`
	End    time.Time `gorm:"not null;default:'1000-1-1';type:date"`

Permission permission model

func (*Permission) BeginS

func (p *Permission) BeginS() string

BeginS begin to string

func (*Permission) Enable

func (p *Permission) Enable() bool

Enable is enable?

func (*Permission) EndS

func (p *Permission) EndS() string

EndS end to string

type Role

type Role struct {

	Name         string `gorm:"not null;index;type:VARCHAR(255)"`
	ResourceType string `gorm:"not null;default:'-';index;type:VARCHAR(255)"`
	ResourceID   uint   `gorm:"not null;default:0"`

Role role model

func (Role) String

func (p Role) String() string

type Setting

type Setting struct {

	Key  string `gorm:"not null;unique;type:VARCHAR(255)"`
	Val  []byte `gorm:"not null"`
	Flag bool   `gorm:"not null"`

Setting setting model

type User

type User struct {
	Email    string `gorm:"not null;index;type:VARCHAR(255)" json:"email"`
	UID      string `gorm:"not null;unique_index;type:char(36)" json:"uid"`
	Home     string `gorm:"not null;type:VARCHAR(255)" json:"home"`
	Name     string `gorm:"not null;type:VARCHAR(255)" json:"name"`
	Password string `gorm:"not null;default:'-';type:VARCHAR(500)" json:"-"`

	ProviderType string `gorm:"not null;default:'unknown';index;type:VARCHAR(255)" json:"provider_type"`
	ProviderID   string `gorm:"not null;index;type:VARCHAR(255)" json:"provider_id"`

	LastSignIn  *time.Time `json:"last_sign_in"`
	SignInCount uint       `gorm:"not null;default:0" json:"sign_in_count"`
	ConfirmedAt *time.Time `json:"confirmed_at"`
	LockedAt    *time.Time `json:"locked_at"`

	Permissions []Permission `json:"permissions"`
	Logs        []Log        `json:"logs"`

User user model

func (*User) IsAvailable

func (p *User) IsAvailable() bool

IsAvailable is valid?

func (*User) IsConfirmed

func (p *User) IsConfirmed() bool

IsConfirmed confirmed?

func (*User) IsLocked

func (p *User) IsLocked() bool

IsLocked locked?

func (*User) SetGravatar

func (p *User) SetGravatar()

SetGravatar set logo by gravatar

func (User) String

func (p User) String() string

Jump to

Keyboard shortcuts

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