data

package
v0.0.0-...-fa05059 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2024 License: MIT, MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Secret 使用Kong生成的密钥和密文信息
	Secret  = []byte("HvtqM5Exc9QqLKY61fPHuU85nPAJyuoo")
	Secret2 = []byte("eBjPE1m8gUxsgtQ706DuHzM23AwrBc8F")
	Key     = "wQkDdN53pk2voNJX5scgme8aNaAUh0ct"
)

ProviderSet is data providers.

Functions

func InitTables

func InitTables(db *gorm.DB) error

func NewDB

func NewDB(c *conf.Data) (*gorm.DB, error)

NewDB initializes the database.

func NewLogger

func NewLogger() *zap.Logger

NewLogger 将日志输出到控制台

func NewRedis

func NewRedis(c *conf.Data) redis.Cmdable

NewRedis initializes Redis.

func NewSnowflake

func NewSnowflake() *sf.Node

NewSnowflake 初始化雪花节点

func NewUserData

func NewUserData(data *Data, l *zap.Logger, node *sf.Node) biz.UserInteractive

Types

type Data

type Data struct {
	// contains filtered or unexported fields
}

Data .

func NewData

func NewData(c *conf.Data, cs *conf.Service, db *gorm.DB, redis redis.Cmdable, logger log.Logger) (*Data, func(), error)

NewData .

type Handler

type Handler interface {
	SetLoginToken(ctx context.Context, uid int64) (string, string, error)
	SetJWTToken(ctx context.Context, uid int64, ssid string) (string, error)
	ExtractToken(ctx context.Context) string
	CheckSession(ctx context.Context, ssid string) error
	ClearToken(ctx context.Context) error

	GetUserInfo(ctx context.Context, tokenStr string) (*UserClaims, error)
	// contains filtered or unexported methods
}

func NewJWT

func NewJWT(c redis.Cmdable) Handler

type Profile

type Profile struct {
	ID       int64  `gorm:"primaryKey;autoIncrement"`         // 用户资料ID,主键
	UserID   int64  `gorm:"not null;index"`                   // 用户ID,外键
	NickName string `gorm:"size:50"`                          // 昵称,最大长度50
	Avatar   string `gorm:"type:text"`                        // 头像URL
	About    string `gorm:"type:text"`                        // 个人简介
	Birthday string `gorm:"column:birthday;type:varchar(10)"` // 生日
}

Profile 用户资料信息结构体

type RefreshClaims

type RefreshClaims struct {
	jwt.RegisteredClaims
	Uid  int64
	Ssid string
}

type User

type User struct {
	ID           int64   `gorm:"primarykey"`                          // 用户ID,主键
	CreateTime   int64   `gorm:"column:created_at;type:bigint"`       // 创建时间,Unix时间戳
	UpdatedTime  int64   `gorm:"column:updated_at;type:bigint"`       // 更新时间,Unix时间戳
	DeletedTime  int64   `gorm:"column:deleted_at;type:bigint;index"` // 删除时间,Unix时间戳,用于软删除
	PasswordHash string  `gorm:"not null"`                            // 密码哈希值,不能为空
	Deleted      bool    `gorm:"column:deleted;default:false"`        // 删除标志,表示该用户是否被删除
	Email        string  `gorm:"type:varchar(100);uniqueIndex"`       // 邮箱地址,唯一
	Phone        *string `gorm:"type:varchar(15);uniqueIndex"`        // 手机号码,唯一
	Profile      Profile `gorm:"foreignKey:UserID;references:ID"`     // 关联的用户资料
}

User 用户信息结构体

type UserClaims

type UserClaims struct {
	jwt.RegisteredClaims
	Uid         int64
	Ssid        string
	UserAgent   string
	ContentType string
}

type UserData

type UserData struct {
	// contains filtered or unexported fields
}

func (*UserData) ChangePassword

func (ud *UserData) ChangePassword(ctx context.Context, email string, newPassword string) error

func (*UserData) CreateUser

func (ud *UserData) CreateUser(ctx context.Context, u domain.User) error

func (*UserData) DeleteUser

func (ud *UserData) DeleteUser(ctx context.Context, email string, uid int64) error

func (*UserData) FindByEmail

func (ud *UserData) FindByEmail(ctx context.Context, email string) (domain.User, error)

func (*UserData) FindByID

func (ud *UserData) FindByID(ctx context.Context, id int64) (domain.User, error)

func (*UserData) FindByPhone

func (ud *UserData) FindByPhone(ctx context.Context, phone string) (domain.User, error)

func (*UserData) GetProfile

func (ud *UserData) GetProfile(ctx context.Context, userId int64) (domain.Profile, error)

func (*UserData) UpdateProfile

func (ud *UserData) UpdateProfile(ctx context.Context, p domain.Profile) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳