service

package module
v0.0.0-...-32fa971 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2023 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTokenContext

func NewTokenContext(ctx context.Context, token string) context.Context

func NewUserIdContext

func NewUserIdContext(ctx context.Context, id int) context.Context

func TokenFromContext

func TokenFromContext(ctx context.Context) (string, bool)

func UserIdFromContext

func UserIdFromContext(ctx context.Context) (int, bool)

func ValidateToken

func ValidateToken(ctx context.Context, tokenString string, db wrapper.GddDB) (int, bool, error)

Types

type Usersvc

type Usersvc interface {
	// GetUser 用户详情接口
	// 展示如何定义带查询字符串参数的GET请求接口
	// GetUser is user detail api
	// demo how to define get http request with query string parameters
	// @role(USER)
	GetUser(ctx context.Context,

		userId int) (

		data vo.UserVo,

		err error)

	// GetMe 获取当前登录用户详情接口
	// GetMe is used for getting user info from token in header.
	// @role(USER)
	GetMe(ctx context.Context) (

		data vo.UserVo,

		err error)

	// PublicSignUp 用户注册接口
	// 展示如何定义POST请求且Content-Type是application/x-www-form-urlencoded的接口
	// PublicSignUp is user signup api
	// demo how to define post request api which accepts application/x-www-form-urlencoded content-type
	SignUp(ctx context.Context,

		username string,

		password string,
	) (

		data int, err error)

	// PublicLogIn 用户登录接口
	// 展示如何鉴权并返回token
	// PublicLogIn is user login api
	// demo how to do authentication and issue token
	LogIn(ctx context.Context,

		username string,

		password string) (

		data string, err error)

	// GetLogout 注销token
	// GetLogout is used for revoking a token
	// https://github.com/dgrijalva/jwt-go/issues/214
	// @role(USER)
	GetLogout(ctx context.Context) (

		data string,

		err error)

	// PublicTokenValidate token校验接口
	// 如果token有效,返回用户信息,否则返回空对象
	// PublicTokenValidate validates token string
	// if token is valid, return user information, otherwise, return empty data
	GetTokenValidate(ctx context.Context, token string) (user vo.UserVo, err error)
}

Usersvc 用户管理服务 调用用户详情、用户分页和上传头像接口需要带上Bearer Token请求头 用户注册、用户登录和下载头像接口可以公开访问,无须鉴权 Usersvc is user management service You should set Bearer Token header when you request protected endpoints such as user detail, user pagination and upload avatar. You can add doc for whole service here

type UsersvcImpl

type UsersvcImpl struct {
	pb.UnimplementedUsersvcServiceServer
	// contains filtered or unexported fields
}

func NewUsersvc

func NewUsersvc(conf *config.Config, db wrapper.GddDB) *UsersvcImpl

func (*UsersvcImpl) GetLogout

func (receiver *UsersvcImpl) GetLogout(ctx context.Context) (data string, err error)

func (*UsersvcImpl) GetLogoutRpc

func (receiver *UsersvcImpl) GetLogoutRpc(ctx context.Context, request *emptypb.Empty) (*pb.GetLogoutRpcResponse, error)

func (*UsersvcImpl) GetMe

func (receiver *UsersvcImpl) GetMe(ctx context.Context) (data vo.UserVo, err error)

func (*UsersvcImpl) GetMeRpc

func (receiver *UsersvcImpl) GetMeRpc(ctx context.Context, request *emptypb.Empty) (*pb.UserVo, error)

func (*UsersvcImpl) GetTokenValidate

func (receiver *UsersvcImpl) GetTokenValidate(ctx context.Context, token string) (user vo.UserVo, err error)

func (*UsersvcImpl) GetTokenValidateRpc

func (receiver *UsersvcImpl) GetTokenValidateRpc(ctx context.Context, request *pb.GetTokenValidateRpcRequest) (*pb.UserVo, error)

func (*UsersvcImpl) GetUser

func (receiver *UsersvcImpl) GetUser(ctx context.Context, userId int) (data vo.UserVo, err error)

func (*UsersvcImpl) GetUserRpc

func (receiver *UsersvcImpl) GetUserRpc(ctx context.Context, request *pb.GetUserRpcRequest) (*pb.UserVo, error)

func (*UsersvcImpl) LogIn

func (receiver *UsersvcImpl) LogIn(ctx context.Context, username string, password string) (data string, err error)

func (*UsersvcImpl) LogInRpc

func (receiver *UsersvcImpl) LogInRpc(ctx context.Context, request *pb.LogInRpcRequest) (*pb.LogInRpcResponse, error)

func (*UsersvcImpl) SignUp

func (receiver *UsersvcImpl) SignUp(ctx context.Context, username string, password string) (data int, err error)

func (*UsersvcImpl) SignUpRpc

func (receiver *UsersvcImpl) SignUpRpc(ctx context.Context, request *pb.SignUpRpcRequest) (*pb.SignUpRpcResponse, error)

Directories

Path Synopsis
* * Generated by go-doudou v2.0.1.
* * Generated by go-doudou v2.0.1.
internal
lib
transport
grpc
* * Generated by go-doudou v2.0.1.
* * Generated by go-doudou v2.0.1.
httpsrv
* * Generated by go-doudou v2.0.1.
* * Generated by go-doudou v2.0.1.

Jump to

Keyboard shortcuts

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