storage

package
v1.15.0 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func StoreMigrate

func StoreMigrate(store Store) error

Types

type KeyPair

type KeyPair struct {
	Name       string    `gorm:"column:name;type:varchar(50);NOT NULL"`
	Perm       string    `gorm:"column:perm;type:varchar(50);NOT NULL"`
	Secret     string    `gorm:"column:secret;type:varchar(255);NOT NULL"`
	Extra      string    `gorm:"column:extra;type:varchar(255);"`
	Token      Token     `gorm:"column:token;type:varchar(512);uniqueIndex:token_token_IDX,type:hash;not null"`
	CreateTime time.Time `gorm:"column:createTime;type:datetime;NOT NULL"`
	IsDeleted  int       `gorm:"column:is_deleted;index;default:0;NOT NULL"`
}

func (*KeyPair) Bytes

func (kp *KeyPair) Bytes() ([]byte, error)

func (*KeyPair) CreateTimeBytes

func (kp *KeyPair) CreateTimeBytes() ([]byte, error)

func (*KeyPair) FromBytes

func (kp *KeyPair) FromBytes(val []byte) error

func (*KeyPair) TableName

func (*KeyPair) TableName() string

type Miner

type Miner struct {
	ID         uint64        `gorm:"column:id;primary_key;bigint(20) unsigned AUTO_INCREMENT"`
	Miner      storedAddress `gorm:"column:miner;type:varchar(128);uniqueIndex:miner_idx;NOT NULL"`
	User       string        `gorm:"column:user;type:varchar(50);NOT NULL"`
	OpenMining *bool         `gorm:"column:open_mining;default:1;comment:0-false,1-true"`
	OrmTimestamp
}

func (*Miner) Bytes

func (m *Miner) Bytes() ([]byte, error)

func (*Miner) FromBytes

func (m *Miner) FromBytes(buf []byte) error

type OrmTimestamp

type OrmTimestamp struct {
	CreatedAt time.Time
	UpdatedAt time.Time
	// Implemented soft delete
	DeletedAt gorm.DeletedAt `gorm:"index"`
}

type Prefix

type Prefix = string
const (
	PrefixToken    Prefix = "TOKEN:"
	PrefixUser     Prefix = "USER:"
	PrefixReqLimit Prefix = "ReqLimit:"
	PrefixMiner    Prefix = "MINERS:"
	PrefixSigner   Prefix = "SIGNERS:"
)

type ReqLimit

type ReqLimit struct {
	Cap      int64
	ResetDur time.Duration
}

func (*ReqLimit) Scan

func (rl *ReqLimit) Scan(value interface{}) error

func (ReqLimit) Value

func (rl ReqLimit) Value() (driver.Value, error)

type Signer

type Signer struct {
	ID     uint64        `gorm:"column:id;primary_key;bigint(20) unsigned AUTO_INCREMENT;"`
	Signer storedAddress `gorm:"column:signer;type:varchar(128);uniqueIndex:user_signer_idx,priority:2;NOT NULL"`
	User   string        `gorm:"column:user;type:varchar(50);uniqueIndex:user_signer_idx,priority:1;NOT NULL"`
	OrmTimestamp
}

func (*Signer) Bytes

func (m *Signer) Bytes() ([]byte, error)

func (*Signer) FromBytes

func (m *Signer) FromBytes(buf []byte) error

type Store

type Store interface {
	// token
	Get(token Token) (*KeyPair, error)
	ByName(name string) ([]*KeyPair, error)
	Put(kp *KeyPair) error
	Delete(token Token) error
	Recover(token Token) error
	Has(token Token) (bool, error)
	List(skip, limit int64) ([]*KeyPair, error)
	UpdateToken(kp *KeyPair) error

	// user
	HasUser(name string) (bool, error)
	GetUser(name string) (*User, error)
	VerifyUsers(names []string) error
	PutUser(*User) error
	UpdateUser(*User) error
	ListUsers(skip, limit int64, state core.UserState) ([]*User, error)
	DeleteUser(name string) error
	RecoverUser(name string) error

	// rate limit
	GetRateLimits(name, id string) ([]*UserRateLimit, error)
	PutRateLimit(limit *UserRateLimit) (string, error)
	DelRateLimit(name, id string) error

	// miner-user(1-1)
	// first returned bool, 'miner' is created(true) or updated(false)
	UpsertMiner(mAddr address.Address, userName string, openMining *bool) (bool, error)
	HasMiner(mAddr address.Address) (bool, error)
	MinerExistInUser(mAddr address.Address, userName string) (bool, error)
	GetUserByMiner(mAddr address.Address) (*User, error)
	ListMiners(user string) ([]*Miner, error)
	// first returned bool, if miner exists(true) or false
	DelMiner(mAddr address.Address) (bool, error)

	// signer-user(n-n)
	RegisterSigner(addr address.Address, userName string) error
	SignerExistInUser(addr address.Address, userName string) (bool, error)
	ListSigner(userName string) ([]*Signer, error)
	UnregisterSigner(addr address.Address, userName string) error
	// has signer in system
	HasSigner(addr address.Address) (bool, error)
	// delete all signers
	DelSigner(addr address.Address) (bool, error)
	// all users including the specified signer
	GetUserBySigner(addr address.Address) ([]*User, error)

	Version() (uint64, error)
	MigrateToV1() error
	MigrateToV2() error
	MigrateToV3() error
}

func NewStore

func NewStore(cnf *config.DBConfig, dataPath string) (Store, error)

type StoreVersion

type StoreVersion struct {
	ID      uint64 `grom:"primary_key"`
	Version uint64 `gorm:"column:version"`
}

func (*StoreVersion) Bytes

func (s *StoreVersion) Bytes() ([]byte, error)

func (*StoreVersion) FromBytes

func (s *StoreVersion) FromBytes(bytes []byte) error

type Token

type Token string

func (Token) Bytes

func (t Token) Bytes() []byte

func (Token) String

func (t Token) String() string

type User

type User struct {
	Id         string         `gorm:"column:id;type:varchar(64);primary_key"`
	Name       string         `gorm:"column:name;type:varchar(50);uniqueIndex:users_name_IDX,type:btree;not null"`
	Comment    string         `gorm:"column:comment;type:varchar(255);"`
	State      core.UserState `gorm:"column:state;type:tinyint(4);default:0;NOT NULL"`
	CreateTime time.Time      `gorm:"column:createTime;type:datetime;NOT NULL"`
	UpdateTime time.Time      `gorm:"column:updateTime;type:datetime;NOT NULL"`
	IsDeleted  int            `gorm:"column:is_deleted;index;default:0;NOT NULL"`
}

func (*User) Bytes

func (u *User) Bytes() ([]byte, error)

func (*User) CreateTimeBytes

func (u *User) CreateTimeBytes() ([]byte, error)

func (*User) FromBytes

func (u *User) FromBytes(buff []byte) error

func (*User) TableName

func (*User) TableName() string

type UserRateLimit

type UserRateLimit struct {
	Id       string   `gorm:"column:id;type:varchar(64);primary_key"`
	Name     string   `gorm:"column:name;type:varchar(50);index:user_service_api_IDX;not null" binding:"required"`
	Service  string   `gorm:"column:service;type:varchar(50);index:user_service_api_IDX"`
	API      string   `gorm:"column:api;type:varchar(50);index:user_service_api_IDX"`
	ReqLimit ReqLimit `gorm:"column:reqLimit;type:varchar(256)"`
}

we are perpose to support limit user requests with `Service`/`Service.API` ferther, so we add their declar in `UserRateLimit`

func (*UserRateLimit) LimitKey

func (l *UserRateLimit) LimitKey() string

Jump to

Keyboard shortcuts

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