Documentation ¶
Index ¶
- Constants
- Variables
- func CtxGetSessId(ctx context.Context) string
- func SupportedPlatform(p string) bool
- func TransformPlatform(p string) string
- func WithSessId(ctx context.Context, sessId string) context.Context
- func WithUserInfo(ctx context.Context, user *UserInfo) context.Context
- type AvatarInfoRequest
- type CheckInResponse
- type JsonSessionSerializer
- type MsgpackSessionSerializer
- type PassCheckInRequest
- type SendSmsRequest
- type SendSmsResponse
- type Session
- type SessionMeta
- type SessionSerializer
- type SmsCheckInRequest
- type UpdateUserRequest
- type UploadUserAvatarResponse
- type UserInfo
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 SupportedPlatform ¶
func TransformPlatform ¶
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)
type MsgpackSessionSerializer ¶
type MsgpackSessionSerializer struct{}
func (MsgpackSessionSerializer) Deserialize ¶
func (s MsgpackSessionSerializer) Deserialize(data []byte) (*Session, error)
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 ¶
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 NewUserInfoFromUserBase ¶
func (*UserInfo) ToUserBase ¶
Click to show internal directories.
Click to hide internal directories.