model

package
v0.0.0-...-d80f745 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CtxUserInfoKey = "__CtxUserInfoKey__"
	CtxSessIdKey   = "__CtxSessIdKey__"
)
View Source
const (
	SessionStatusInited  int8 = 0
	SessionStatusActive  int8 = 1
	SessionStatusExpired int8 = 2
	SessionStatusKicked  int8 = 3
)
View Source
const (
	MaxNicknameLen  = 20
	MaxStyleSignLen = 64
	MaxAvatarBytes  = 500 * 1024
)
View Source
const (
	Web = "web"
)

支持的平台

View Source
const (
	// do not easily change this constant
	WhimerSessId = "WHIMERSESSID"
)

Variables

View Source
var (
	GenderMap = map[int8]string{
		0: "保密",
		1: "男",
		2: "女",
	}

	GenderMapConvert = map[string]int8{
		"保密": 0,
		"男":  1,
		"女":  2,
	}
)

Functions

func CtxGetSessId

func CtxGetSessId(ctx context.Context) string

func SupportedPlatform

func SupportedPlatform(p string) bool

func TransformPlatform

func TransformPlatform(p string) string

func WithSessId

func WithSessId(ctx context.Context, sessId string) context.Context

func WithUserInfo

func WithUserInfo(ctx context.Context, user *UserInfo) context.Context

Types

type AvatarInfoRequest

type AvatarInfoRequest struct {
	Filename    string `json:"filename"`
	Ext         string `json:"ext"`
	ContentType string `json:"content_type"`
	Size        int64  `json:"size"`
	Content     []byte `json:"-"`
}

校验上传的文件元信息

func ParseAvatarFile

func ParseAvatarFile(file multipart.File, header *multipart.FileHeader) (*AvatarInfoRequest, error)

func (*AvatarInfoRequest) String

func (r *AvatarInfoRequest) String() string

type CheckInResponse

type CheckInResponse struct {
	Uid       uint64   `json:"uid"`
	Nickname  string   `json:"nickname"`
	StyleSign string   `json:"style_sign"`
	Avatar    string   `json:"avatar"`
	Gender    string   `json:"gender"`
	CreateAt  int64    `json:"create_at"`
	Session   *Session `json:"-"`
}

登录成功返回结果 需要包含登录成功的用户信息

func NewCheckInResponseFromUserInfo

func NewCheckInResponseFromUserInfo(u *UserInfo) *CheckInResponse

type JsonSessionSerializer

type JsonSessionSerializer struct{}

func (JsonSessionSerializer) Deserialize

func (s JsonSessionSerializer) Deserialize(data []byte) (*Session, error)

func (JsonSessionSerializer) Serialize

func (s JsonSessionSerializer) Serialize(sess *Session) ([]byte, error)

type MsgpackSessionSerializer

type MsgpackSessionSerializer struct{}

func (MsgpackSessionSerializer) Deserialize

func (s MsgpackSessionSerializer) Deserialize(data []byte) (*Session, error)

func (MsgpackSessionSerializer) Serialize

func (s MsgpackSessionSerializer) Serialize(sess *Session) ([]byte, error)

type PassCheckInRequest

type PassCheckInRequest struct {
}

密码登录

type SendSmsRequest

type SendSmsRequest struct {
	Tel  string `json:"tel"`           // 手机号
	Zone string `json:"zone,optional"` // TODO 手机区号

}

发送短信

func (*SendSmsRequest) Validate

func (r *SendSmsRequest) Validate() error

type SendSmsResponse

type SendSmsResponse struct {
}

type Session

type Session struct {
	Meta     SessionMeta `json:"meta"`
	Uid      uint64      `json:"uid"`
	Platform string      `json:"platform"` // session对应平台
	Detail   string      `json:"detail"`   // 用户详细信息
}

用户session信息

func NewSession

func NewSession(id string, expireAt int64) *Session

func (*Session) Cookie

func (s *Session) Cookie() *http.Cookie

type SessionMeta

type SessionMeta struct {
	Id       string `json:"id"`
	ExpireAt int64  `json:"expire_at"` // 过期时间 unix second timestamp
	Status   int8   `json:"status"`    // session 状态
}

session元数据

func (*SessionMeta) IsExpired

func (m *SessionMeta) IsExpired() bool

type SessionSerializer

type SessionSerializer interface {
	Serialize(s *Session) ([]byte, error)
	Deserialize([]byte) (*Session, error)
}

session序列化

type SmsCheckInRequest

type SmsCheckInRequest struct {
	Tel      string `json:"tel"`
	Zone     string `json:"zone,optional"`
	Code     string `json:"code"` // 短信验证码
	Platform string `json:"platform"`
}

手机+短信验证码登录

func (*SmsCheckInRequest) Validate

func (r *SmsCheckInRequest) Validate() error

type UpdateUserRequest

type UpdateUserRequest struct {
	Uid       uint64 `json:"uid"`
	Nickname  string `json:"nickname"`
	StyleSign string `json:"style_sign"`
	Gender    int8   `json:"gender"`
}

func (*UpdateUserRequest) Validate

func (r *UpdateUserRequest) Validate() error

type UploadUserAvatarResponse

type UploadUserAvatarResponse struct {
	Url string `json:"avatar_url"`
}

上传头像响应结果

type UserInfo

type UserInfo struct {
	Uid       uint64 `json:"uid"`
	Nickname  string `json:"nickname"`
	Avatar    string `json:"avatar,omitempty"`
	StyleSign string `json:"style_sign"`
	Gender    string `json:"gender"`
}

可以返回给各端的个人信息

func CtxGetUserInfo

func CtxGetUserInfo(ctx context.Context) *UserInfo

func NewUserInfoFromUserBase

func NewUserInfoFromUserBase(user *dao.UserBase) *UserInfo

func (*UserInfo) ToPb

func (u *UserInfo) ToPb() *userv1.UserInfo

func (*UserInfo) ToUserBase

func (u *UserInfo) ToUserBase() *dao.UserBase

Jump to

Keyboard shortcuts

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