service

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2022 License: MIT Imports: 17 Imported by: 0

README

service

  • 业务逻辑层,处于 handler 层和 repository 层之间
  • service 只能通过 repository 层获取数据
  • 面向接口编程
  • 依赖接口,不要依赖实现
  • 如果有事务处理,在这一层进行处理
  • 如果是调用的第三方服务,请不要加 cache, 避免缓存不一致(对方更新数据,这边无法知晓)
  • 由于 service 会被 httprpc 调用,默认会提供 http 调用的,比如:GetUserInfo(), 如果 rpc 需要调用,可以对 GetUserInfo() 进行一层封装, 比如:GetUser()

Reference

Documentation

Index

Constants

View Source
const (
	// FollowStatusNormal 关注状态-正常
	FollowStatusNormal int = 1 // 正常
	// FollowStatusDelete 关注状态-删除
	FollowStatusDelete = 0 // 删除
)
View Source
const (
	// DefaultLimit 默认分页数
	DefaultLimit = 50

	// MaxID 最大id
	MaxID = 0xffffffffffff

	// DefaultAvatar 默认头像 key
	DefaultAvatar = "default_avatar.png"
)

Variables

This section is empty.

Functions

func GetUserID

func GetUserID(c *gin.Context) uint64

GetUserID 返回用户id

func TransferUser

func TransferUser(input *TransferUserInput) *model.UserInfo

TransferUser 组装数据并输出 对外暴露的user结构,都应该经过此结构进行转换

Types

type RelationService

type RelationService interface {
	Follow(ctx context.Context, userID uint64, followedUID uint64) error
	Unfollow(ctx context.Context, userID uint64, followedUID uint64) error
	IsFollowing(ctx context.Context, userID uint64, followedUID uint64) bool
	GetFollowingUserList(ctx context.Context, userID uint64, lastID uint64, limit int) ([]*model.UserFollowModel, error)
	GetFollowerUserList(ctx context.Context, userID uint64, lastID uint64, limit int) ([]*model.UserFansModel, error)
}

RelationService .

type SMSService

type SMSService interface {
	SendSMS(phoneNumber string, verifyCode int) error
}

SMSService define interface func

type Service

type Service interface {
	Users() UserService
	Relations() RelationService
	SMS() SMSService
	VCode() VCodeService
}

Service define all service

var Svc Service

Svc global var

func New

func New(repo repository.Repository) Service

New init service

type TransferUserInput

type TransferUserInput struct {
	CurUser  *model.UserBaseModel
	User     *model.UserBaseModel
	UserStat *model.UserStatModel
	IsFollow int `json:"is_follow"`
	IsFans   int `json:"is_fans"`
}

TransferUserInput 转换输入字段

type UserService

type UserService interface {
	Register(ctx context.Context, username, email, password string) error
	EmailLogin(ctx context.Context, email, password string) (tokenStr string, err error)
	PhoneLogin(ctx context.Context, phone int64, verifyCode int) (tokenStr string, err error)
	// LoginByPhone(ctx context.Context, req *pb.PhoneLoginRequest) (reply *pb.PhoneLoginReply, err error)
	GetUserByID(ctx context.Context, id uint64) (*model.UserBaseModel, error)
	GetUserInfoByID(ctx context.Context, id uint64) (*model.UserInfo, error)
	GetUserByPhone(ctx context.Context, phone int64) (*model.UserBaseModel, error)
	GetUserByEmail(ctx context.Context, email string) (*model.UserBaseModel, error)
	UpdateUser(ctx context.Context, id uint64, userMap map[string]interface{}) error
	BatchGetUsers(ctx context.Context, userID uint64, userIDs []uint64) ([]*model.UserInfo, error)
}

UserService define interface func

type VCodeService

type VCodeService interface {
	GenLoginVCode(phone string) (int, error)
	CheckLoginVCode(phone int64, vCode int) bool
	GetLoginVCode(phone int64) (int, error)
}

VCodeService define interface func

Jump to

Keyboard shortcuts

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