🚚 Move http server package
This commit is contained in:
@ -18,7 +18,7 @@ type authenticateServer struct {
|
||||
proto.UnimplementedAuthServiceServer
|
||||
}
|
||||
|
||||
func (v *Server) Authenticate(_ context.Context, in *proto.AuthRequest) (*proto.AuthReply, error) {
|
||||
func (v *App) Authenticate(_ context.Context, in *proto.AuthRequest) (*proto.AuthReply, error) {
|
||||
ticket, perms, err := services.Authenticate(uint(in.GetSessionId()))
|
||||
if err != nil {
|
||||
return &proto.AuthReply{
|
||||
@ -43,7 +43,7 @@ func (v *Server) Authenticate(_ context.Context, in *proto.AuthRequest) (*proto.
|
||||
}
|
||||
}
|
||||
|
||||
func (v *Server) EnsurePermGranted(_ context.Context, in *proto.CheckPermRequest) (*proto.CheckPermResponse, error) {
|
||||
func (v *App) EnsurePermGranted(_ context.Context, in *proto.CheckPermRequest) (*proto.CheckPermResponse, error) {
|
||||
ctx, err := services.GetAuthContext(uint(in.GetSessionId()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -63,7 +63,7 @@ func (v *Server) EnsurePermGranted(_ context.Context, in *proto.CheckPermRequest
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) EnsureUserPermGranted(_ context.Context, in *proto.CheckUserPermRequest) (*proto.CheckUserPermResponse, error) {
|
||||
func (v *App) EnsureUserPermGranted(_ context.Context, in *proto.CheckUserPermRequest) (*proto.CheckUserPermResponse, error) {
|
||||
relation, err := services.GetRelationWithTwoNode(uint(in.GetUserId()), uint(in.GetOtherId()))
|
||||
if err != nil {
|
||||
return &proto.CheckUserPermResponse{
|
||||
@ -82,7 +82,7 @@ func (v *Server) EnsureUserPermGranted(_ context.Context, in *proto.CheckUserPer
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) ListUserFriends(_ context.Context, in *proto.ListUserRelativeRequest) (*proto.ListUserRelativeResponse, error) {
|
||||
func (v *App) ListUserFriends(_ context.Context, in *proto.ListUserRelativeRequest) (*proto.ListUserRelativeResponse, error) {
|
||||
tx := database.C.Preload("Account").Where("status = ?", models.RelationshipFriend)
|
||||
|
||||
if in.GetIsRelated() {
|
||||
@ -108,7 +108,7 @@ func (v *Server) ListUserFriends(_ context.Context, in *proto.ListUserRelativeRe
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) ListUserBlocklist(_ context.Context, in *proto.ListUserRelativeRequest) (*proto.ListUserRelativeResponse, error) {
|
||||
func (v *App) ListUserBlocklist(_ context.Context, in *proto.ListUserRelativeRequest) (*proto.ListUserRelativeResponse, error) {
|
||||
tx := database.C.Preload("Account").Where("status = ?", models.RelationshipBlocked)
|
||||
|
||||
if in.GetIsRelated() {
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
||||
)
|
||||
|
||||
func (v *Server) RecordEvent(ctx context.Context, request *proto.RecordEventRequest) (*proto.RecordEventResponse, error) {
|
||||
func (v *App) RecordEvent(ctx context.Context, request *proto.RecordEventRequest) (*proto.RecordEventResponse, error) {
|
||||
services.AddEvent(
|
||||
uint(request.GetUserId()),
|
||||
request.GetAction(),
|
||||
|
@ -6,13 +6,13 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
func (v *Server) Check(ctx context.Context, request *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
|
||||
func (v *App) Check(ctx context.Context, request *health.HealthCheckRequest) (*health.HealthCheckResponse, error) {
|
||||
return &health.HealthCheckResponse{
|
||||
Status: health.HealthCheckResponse_SERVING,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) Watch(request *health.HealthCheckRequest, server health.Health_WatchServer) error {
|
||||
func (v *App) Watch(request *health.HealthCheckRequest, server health.Health_WatchServer) error {
|
||||
for {
|
||||
if server.Send(&health.HealthCheckResponse{
|
||||
Status: health.HealthCheckResponse_SERVING,
|
||||
|
@ -14,7 +14,7 @@ import (
|
||||
"git.solsynth.dev/hydrogen/passport/pkg/proto"
|
||||
)
|
||||
|
||||
func (v *Server) NotifyUser(_ context.Context, in *proto.NotifyUserRequest) (*proto.NotifyResponse, error) {
|
||||
func (v *App) NotifyUser(_ context.Context, in *proto.NotifyUserRequest) (*proto.NotifyResponse, error) {
|
||||
var err error
|
||||
var user models.Account
|
||||
if user, err = services.GetAccount(uint(in.GetUserId())); err != nil {
|
||||
@ -52,7 +52,7 @@ func (v *Server) NotifyUser(_ context.Context, in *proto.NotifyUserRequest) (*pr
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) NotifyUserBatch(_ context.Context, in *proto.NotifyUserBatchRequest) (*proto.NotifyResponse, error) {
|
||||
func (v *App) NotifyUserBatch(_ context.Context, in *proto.NotifyUserBatchRequest) (*proto.NotifyResponse, error) {
|
||||
var err error
|
||||
var users []models.Account
|
||||
if users, err = services.GetAccountList(lo.Map(in.GetUserId(), func(item uint64, index int) uint {
|
||||
@ -101,7 +101,7 @@ func (v *Server) NotifyUserBatch(_ context.Context, in *proto.NotifyUserBatchReq
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) NotifyAllUser(_ context.Context, in *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||
func (v *App) NotifyAllUser(_ context.Context, in *proto.NotifyRequest) (*proto.NotifyResponse, error) {
|
||||
var users []models.Account
|
||||
if err := database.C.Find(&users).Error; err != nil {
|
||||
return nil, fmt.Errorf("unable to get account: %v", err)
|
||||
|
@ -12,7 +12,7 @@ import (
|
||||
"github.com/samber/lo"
|
||||
)
|
||||
|
||||
func (v *Server) ListCommunityRealm(ctx context.Context, empty *proto.ListRealmRequest) (*proto.ListRealmResponse, error) {
|
||||
func (v *App) ListCommunityRealm(ctx context.Context, empty *proto.ListRealmRequest) (*proto.ListRealmResponse, error) {
|
||||
realms, err := services.ListCommunityRealm()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -40,7 +40,7 @@ func (v *Server) ListCommunityRealm(ctx context.Context, empty *proto.ListRealmR
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) ListAvailableRealm(ctx context.Context, request *proto.LookupUserRealmRequest) (*proto.ListRealmResponse, error) {
|
||||
func (v *App) ListAvailableRealm(ctx context.Context, request *proto.LookupUserRealmRequest) (*proto.ListRealmResponse, error) {
|
||||
account, err := services.GetAccount(uint(request.GetUserId()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to find target account: %v", err)
|
||||
@ -72,7 +72,7 @@ func (v *Server) ListAvailableRealm(ctx context.Context, request *proto.LookupUs
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) ListOwnedRealm(ctx context.Context, request *proto.LookupUserRealmRequest) (*proto.ListRealmResponse, error) {
|
||||
func (v *App) ListOwnedRealm(ctx context.Context, request *proto.LookupUserRealmRequest) (*proto.ListRealmResponse, error) {
|
||||
account, err := services.GetAccount(uint(request.GetUserId()))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to find target account: %v", err)
|
||||
@ -104,7 +104,7 @@ func (v *Server) ListOwnedRealm(ctx context.Context, request *proto.LookupUserRe
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) GetRealm(ctx context.Context, request *proto.LookupRealmRequest) (*proto.RealmInfo, error) {
|
||||
func (v *App) GetRealm(ctx context.Context, request *proto.LookupRealmRequest) (*proto.RealmInfo, error) {
|
||||
var realm models.Realm
|
||||
|
||||
tx := database.C.Model(&models.Realm{})
|
||||
@ -143,7 +143,7 @@ func (v *Server) GetRealm(ctx context.Context, request *proto.LookupRealmRequest
|
||||
return info, nil
|
||||
}
|
||||
|
||||
func (v *Server) ListRealmMember(ctx context.Context, request *proto.RealmMemberLookupRequest) (*proto.ListRealmMemberResponse, error) {
|
||||
func (v *App) ListRealmMember(ctx context.Context, request *proto.RealmMemberLookupRequest) (*proto.ListRealmMemberResponse, error) {
|
||||
var members []models.RealmMember
|
||||
if request.UserId == nil && request.RealmId == nil {
|
||||
return nil, fmt.Errorf("either user id or realm id must be provided")
|
||||
@ -171,7 +171,7 @@ func (v *Server) ListRealmMember(ctx context.Context, request *proto.RealmMember
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) GetRealmMember(ctx context.Context, request *proto.RealmMemberLookupRequest) (*proto.RealmMemberInfo, error) {
|
||||
func (v *App) GetRealmMember(ctx context.Context, request *proto.RealmMemberLookupRequest) (*proto.RealmMemberInfo, error) {
|
||||
var member models.RealmMember
|
||||
if request.UserId == nil && request.RealmId == nil {
|
||||
return nil, fmt.Errorf("either user id or realm id must be provided")
|
||||
@ -195,7 +195,7 @@ func (v *Server) GetRealmMember(ctx context.Context, request *proto.RealmMemberL
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (v *Server) CheckRealmMemberPerm(ctx context.Context, request *proto.CheckRealmPermRequest) (*proto.CheckRealmPermResponse, error) {
|
||||
func (v *App) CheckRealmMemberPerm(ctx context.Context, request *proto.CheckRealmPermRequest) (*proto.CheckRealmPermResponse, error) {
|
||||
var member models.RealmMember
|
||||
tx := database.C.
|
||||
Where("realm_id = ?", request.GetRealmId()).
|
||||
|
@ -13,7 +13,7 @@ import (
|
||||
health "google.golang.org/grpc/health/grpc_health_v1"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
type App struct {
|
||||
nroto.UnimplementedAuthServiceServer
|
||||
nroto.UnimplementedDirectoryServiceServer
|
||||
proto.UnimplementedNotifierServer
|
||||
@ -24,8 +24,8 @@ type Server struct {
|
||||
srv *grpc.Server
|
||||
}
|
||||
|
||||
func NewServer() *Server {
|
||||
server := &Server{
|
||||
func NewServer() *App {
|
||||
server := &App{
|
||||
srv: grpc.NewServer(),
|
||||
}
|
||||
|
||||
@ -40,7 +40,7 @@ func NewServer() *Server {
|
||||
return server
|
||||
}
|
||||
|
||||
func (v *Server) Listen() error {
|
||||
func (v *App) Listen() error {
|
||||
listener, err := net.Listen("tcp", viper.GetString("grpc_bind"))
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"git.solsynth.dev/hypernet/nexus/pkg/proto"
|
||||
)
|
||||
|
||||
func (v *Server) BroadcastEvent(ctx context.Context, request *proto.EventInfo) (*proto.EventResponse, error) {
|
||||
func (v *App) BroadcastEvent(ctx context.Context, request *proto.EventInfo) (*proto.EventResponse, error) {
|
||||
switch request.GetEvent() {
|
||||
case "ws.client.register":
|
||||
// No longer need update user online status
|
||||
|
Reference in New Issue
Block a user