package corrpc import ( context "context" "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc" cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types" ) type UserService interface { UserLogin(ctx context.Context, msg *UserLogin) (*UserLoginResp, *rpc.CodeError) UserLogout(ctx context.Context, msg *UserLogout) (*UserLogoutResp, *rpc.CodeError) UserRefreshToken(ctx context.Context, msg *UserRefreshToken) (*UserRefreshTokenResp, *rpc.CodeError) HubLoadAccessToken(ctx context.Context, msg *HubLoadAccessToken) (*HubLoadAccessTokenResp, *rpc.CodeError) } // 客户端登录 type UserLogin struct { Account string Password string } type UserLoginResp struct { Token cortypes.UserAccessToken PrivateKey string } var _ = NoAuth(Coordinator_UserLogin_FullMethodName) func (c *Client) UserLogin(ctx context.Context, msg *UserLogin) (*UserLoginResp, *rpc.CodeError) { if c.fusedErr != nil { return nil, c.fusedErr } return rpc.UnaryClient[*UserLoginResp](c.cli.UserLogin, ctx, msg) } func (s *Server) UserLogin(ctx context.Context, req *rpc.Request) (*rpc.Response, error) { return rpc.UnaryServer(s.svrImpl.UserLogin, ctx, req) } // 客户端刷新Token,原始Token会继续有效。 type UserRefreshToken struct{} type UserRefreshTokenResp struct { Token cortypes.UserAccessToken PrivateKey string } var _ = TokenAuth(Coordinator_UserLogin_FullMethodName) func (c *Client) UserRefreshToken(ctx context.Context, msg *UserRefreshToken) (*UserRefreshTokenResp, *rpc.CodeError) { if c.fusedErr != nil { return nil, c.fusedErr } return rpc.UnaryClient[*UserRefreshTokenResp](c.cli.UserRefreshToken, ctx, msg) } func (s *Server) UserRefreshToken(ctx context.Context, req *rpc.Request) (*rpc.Response, error) { return rpc.UnaryServer(s.svrImpl.UserRefreshToken, ctx, req) } // 客户端登出。会使用GRPC元数据中的TokenID和UserID来查找Token并删除。 type UserLogout struct{} type UserLogoutResp struct{} var _ = TokenAuth(Coordinator_UserLogout_FullMethodName) func (c *Client) UserLogout(ctx context.Context, msg *UserLogout) (*UserLogoutResp, *rpc.CodeError) { if c.fusedErr != nil { return nil, c.fusedErr } return rpc.UnaryClient[*UserLogoutResp](c.cli.UserLogout, ctx, msg) } func (s *Server) UserLogout(ctx context.Context, req *rpc.Request) (*rpc.Response, error) { return rpc.UnaryServer(s.svrImpl.UserLogout, ctx, req) } // Hub服务加载AccessToken type HubLoadAccessToken struct { HubID cortypes.HubID UserID cortypes.UserID TokenID cortypes.AccessTokenID } type HubLoadAccessTokenResp struct { Token cortypes.UserAccessToken } func (c *Client) HubLoadAccessToken(ctx context.Context, msg *HubLoadAccessToken) (*HubLoadAccessTokenResp, *rpc.CodeError) { if c.fusedErr != nil { return nil, c.fusedErr } return rpc.UnaryClient[*HubLoadAccessTokenResp](c.cli.HubLoadAccessToken, ctx, msg) } func (s *Server) HubLoadAccessToken(ctx context.Context, req *rpc.Request) (*rpc.Response, error) { return rpc.UnaryServer(s.svrImpl.HubLoadAccessToken, ctx, req) }