models

package
v0.0.0-...-1f200ce Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	VSub = "vsub"

	UserCollection  = "user"
	NodeCollection  = "node"
	ShareCollection = "share"
)
View Source
const (
	MiddwareKeyLogger  = "Logger"
	MiddwareKeyMongodb = "Mongodb"
	MiddwareKeySession = "Session"
	MiddwareKeyUserID  = "UserID"
)

Variables

View Source
var ErrIsExist = errors.New("Is exist.")
View Source
var RegexpPwd = regexp.MustCompile(`^[A-Za-z0-9]{1,64}$`)

RegexpPwd is regexp with sha256 password

View Source
var RegexpUser = regexp.MustCompile(`^[A-Za-z0-9.+-_@]{3,30}$`)

RegexpUser is regexp with username

Functions

func DeleteNodeByUserID

func DeleteNodeByUserID(db *mgo.Session, id bson.ObjectId) error

func DeleteShareByUserID

func DeleteShareByUserID(db *mgo.Session, id bson.ObjectId) error

func DeleteUserByID

func DeleteUserByID(db *mgo.Session, id bson.ObjectId) error

func Error

func Error(v ...interface{}) error

func ErrorConvert

func ErrorConvert(err error) error

func Errorf

func Errorf(format string, v ...interface{}) error

func LoadShareFromRemote

func LoadShareFromRemote(address string) ([]byte, error)

func PasswordVerify

func PasswordVerify(password, hashedPassword string) error

PasswordVerify verify original password with bcrypt password

func RemoveNodeFromShare

func RemoveNodeFromShare(db *mgo.Session, userID, nodeID bson.ObjectId) error

Types

type ErrorBody

type ErrorBody struct {
	Code int    `json:"code"`
	Msg  string `json:"msg,omitempty"`
}

func NewErrorBody

func NewErrorBody(code int, msg ...interface{}) *ErrorBody

type Node

type Node struct {
	ID     bson.ObjectId `json:"id" bson:"_id,omitempty"`
	UserID bson.ObjectId `json:"user_id" bson:"user_id"`
	Class  string        `json:"class" bson:"class"` // v2ray, ss, ssr

	V2ray *NodeV2ray `json:"v2ray,omitempty" bson:"v2ray,omitempty"`
}

func FindNodeByID

func FindNodeByID(db *mgo.Session, id bson.ObjectId) (*Node, error)

func ListNodeByFilter

func ListNodeByFilter(db *mgo.Session, m bson.M) ([]*Node, error)

func ListNodeByUserID

func ListNodeByUserID(db *mgo.Session, id bson.ObjectId) ([]*Node, error)

func (*Node) Create

func (node *Node) Create(db *mgo.Session) error

func (*Node) Delete

func (node *Node) Delete(db *mgo.Session) error

func (*Node) Update

func (node *Node) Update(db *mgo.Session) error

type NodeV2ray

type NodeV2ray struct {
	Port string `json:"port" bson:"port"`
	Ps   string `json:"ps" bson:"ps"`
	Tls  string `json:"tls" bson:"tls"`
	ID   string `json:"id" bson:"id"`
	Aid  string `json:"aid" bson:"aid"`
	V    string `json:"v" bson:"v"`
	Host string `json:"host" bson:"host"`
	Type string `json:"type" bson:"type"`
	Path string `json:"path" bson:"path"`
	Net  string `json:"net" bson:"net"`
	Add  string `json:"add" bson:"add"`
}

func DecodeV2ray

func DecodeV2ray(data string) (*NodeV2ray, error)

type Share

type Share struct {
	ID     bson.ObjectId   `json:"id" bson:"_id,omitempty"`
	UserID bson.ObjectId   `json:"user_id" bson:"user_id"`
	Key    string          `json:"key" bson:"key"`
	Name   string          `json:"name" bson:"name"`
	NodeID []bson.ObjectId `json:"node_id,omitempty" bson:"node_id,omitempty"`
}

func FindShareByID

func FindShareByID(db *mgo.Session, id bson.ObjectId) (*Share, error)

func FindShareByKey

func FindShareByKey(db *mgo.Session, key string) (*Share, error)

func ListShareByUserID

func ListShareByUserID(db *mgo.Session, id bson.ObjectId) ([]*Share, error)

func (*Share) Create

func (share *Share) Create(db *mgo.Session) error

func (*Share) Delete

func (share *Share) Delete(db *mgo.Session) error

func (*Share) Update

func (share *Share) Update(db *mgo.Session) error

type Token

type Token struct {
	//	Base
	Version string    `json:"version" bson:"version"`
	UserID  string    `json:"id" bson:"user_id"`
	Nonce   string    `json:"nonce" bson:"nonce"`
	Expiry  time.Time `json:"expiry" bson:"expiry"`
	Hmac    string    `json:"hmac" bson:"hmac"`
}

Token struct represents the secret token

func NewToken

func NewToken(userID bson.ObjectId, secret string) *Token

NewToken creates a new Token object from a User object and a secret. The user object must have ID field filled.

func ParseToken

func ParseToken(token string) (*Token, error)

ParseToken parses the authencation string and returns a pointer to the result Token object. If the token is invalid in any way, the pointer will be nil and an error will be returned

func (*Token) String

func (t *Token) String() string

Convert the token into a URL safe string so it can be used in http header.

func (*Token) Validate

func (t *Token) Validate(secret string) bool

Validate returns whether the token is an valid token or not.

type User

type User struct {
	ID             bson.ObjectId `json:"id" bson:"_id,omitempty"`
	UserName       string        `json:"username" bson:"username,omitempty"`
	Password       string        `json:"password,omitempty" bson:"-"`
	HashedPassword string        `json:"-" bson:"hashed_password,omitempty"`
	Token          string        `json:"-" bson:"token,omitempty"`
	Expiry         *time.Time    `json:"-" bson:"expiry,omitempty"`
}

func FindUserByID

func FindUserByID(db *mgo.Session, id bson.ObjectId) *User

FindUserByID find a user exists by id

func FindUserByUserName

func FindUserByUserName(db *mgo.Session, name string) (*User, error)

FindUserByUserName find a user exists by username

func (*User) Create

func (user *User) Create(db *mgo.Session) error

func (*User) HashPassword

func (user *User) HashPassword() bool

func (*User) Update

func (user *User) Update(db *mgo.Session) error

Update a user infomation

func (*User) UpdateToken

func (user *User) UpdateToken(db *mgo.Session) error

Jump to

Keyboard shortcuts

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