Support stream controller event emit

This commit is contained in:
LittleSheep 2024-07-20 19:58:54 +08:00
parent 6643d31b1a
commit 27d501d7a7
5 changed files with 37 additions and 7 deletions

View File

@ -4,8 +4,12 @@
<option name="autoReloadType" value="ALL" /> <option name="autoReloadType" value="ALL" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":arrow_up: Upgrade dealer"> <list default="true" id="3fefb2c4-b6f9-466b-a523-53352e8d6f95" name="更改" comment=":sparkles: Support stream controller event emit">
<change afterPath="$PROJECT_DIR$/pkg/internal/grpc/stream.go" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.mod" beforeDir="false" afterPath="$PROJECT_DIR$/go.mod" afterDir="false" />
<change beforePath="$PROJECT_DIR$/go.sum" beforeDir="false" afterPath="$PROJECT_DIR$/go.sum" afterDir="false" />
<change beforePath="$PROJECT_DIR$/pkg/internal/grpc/server.go" beforeDir="false" afterPath="$PROJECT_DIR$/pkg/internal/grpc/server.go" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -152,7 +156,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value=":bug: Fix status query condition" />
<MESSAGE value=":bug: Fix disturbable condition" /> <MESSAGE value=":bug: Fix disturbable condition" />
<MESSAGE value=":sparkles: Admin notify all API" /> <MESSAGE value=":sparkles: Admin notify all API" />
<MESSAGE value=":bug: Fix request body validation" /> <MESSAGE value=":bug: Fix request body validation" />
@ -177,7 +180,8 @@
<MESSAGE value=":recycle: Refactored relation system&#10;:arrow_up: Support new realm &amp; relation api" /> <MESSAGE value=":recycle: Refactored relation system&#10;:arrow_up: Support new realm &amp; relation api" />
<MESSAGE value=":bug: Fix model relation issue" /> <MESSAGE value=":bug: Fix model relation issue" />
<MESSAGE value=":arrow_up: Upgrade dealer" /> <MESSAGE value=":arrow_up: Upgrade dealer" />
<option name="LAST_COMMIT_MESSAGE" value=":arrow_up: Upgrade dealer" /> <MESSAGE value=":sparkles: Support stream controller event emit" />
<option name="LAST_COMMIT_MESSAGE" value=":sparkles: Support stream controller event emit" />
</component> </component>
<component name="VgoProject"> <component name="VgoProject">
<settings-migrated>true</settings-migrated> <settings-migrated>true</settings-migrated>

2
go.mod
View File

@ -6,7 +6,7 @@ toolchain go1.22.1
require ( require (
firebase.google.com/go v3.13.0+incompatible firebase.google.com/go v3.13.0+incompatible
git.solsynth.dev/hydrogen/dealer v0.0.0-20240719153055-607eba001f65 git.solsynth.dev/hydrogen/dealer v0.0.0-20240720114704-037fc8a18c60
git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745 git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745
github.com/go-playground/validator/v10 v10.17.0 github.com/go-playground/validator/v10 v10.17.0
github.com/gofiber/fiber/v2 v2.52.4 github.com/gofiber/fiber/v2 v2.52.4

2
go.sum
View File

@ -21,6 +21,8 @@ git.solsynth.dev/hydrogen/dealer v0.0.0-20240717054512-da433c88615a h1:08YaBgZtk
git.solsynth.dev/hydrogen/dealer v0.0.0-20240717054512-da433c88615a/go.mod h1:oPdUxLy6TFeRxiRC/BoNb3YUNcnSiOnJrzFTnCPSoCA= git.solsynth.dev/hydrogen/dealer v0.0.0-20240717054512-da433c88615a/go.mod h1:oPdUxLy6TFeRxiRC/BoNb3YUNcnSiOnJrzFTnCPSoCA=
git.solsynth.dev/hydrogen/dealer v0.0.0-20240719153055-607eba001f65 h1:p9PIsp5RyrLdlOR7MXyeGBx04v3+1IMEEBBV22fJZPo= git.solsynth.dev/hydrogen/dealer v0.0.0-20240719153055-607eba001f65 h1:p9PIsp5RyrLdlOR7MXyeGBx04v3+1IMEEBBV22fJZPo=
git.solsynth.dev/hydrogen/dealer v0.0.0-20240719153055-607eba001f65/go.mod h1:oPdUxLy6TFeRxiRC/BoNb3YUNcnSiOnJrzFTnCPSoCA= git.solsynth.dev/hydrogen/dealer v0.0.0-20240719153055-607eba001f65/go.mod h1:oPdUxLy6TFeRxiRC/BoNb3YUNcnSiOnJrzFTnCPSoCA=
git.solsynth.dev/hydrogen/dealer v0.0.0-20240720114704-037fc8a18c60 h1:cy58ybsaMHX8lVoCa3bsWkwQGxD4sPmMAMsVYg42kqU=
git.solsynth.dev/hydrogen/dealer v0.0.0-20240720114704-037fc8a18c60/go.mod h1:oPdUxLy6TFeRxiRC/BoNb3YUNcnSiOnJrzFTnCPSoCA=
git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745 h1:40BUsQMNXjqHyytkyF9py1HjTAWlRgO6R57YXUrHNy4= git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745 h1:40BUsQMNXjqHyytkyF9py1HjTAWlRgO6R57YXUrHNy4=
git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745/go.mod h1:FsQGSLTl0gvo+9Jmbot02S72suyF9tFTrzDj70Xhifo= git.solsynth.dev/hydrogen/paperclip v0.0.0-20240622051057-0f56dba45745/go.mod h1:FsQGSLTl0gvo+9Jmbot02S72suyF9tFTrzDj70Xhifo=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=

View File

@ -1,20 +1,22 @@
package grpc package grpc
import ( import (
"google.golang.org/grpc/reflection"
"net" "net"
"google.golang.org/grpc/reflection"
"git.solsynth.dev/hydrogen/dealer/pkg/proto" "git.solsynth.dev/hydrogen/dealer/pkg/proto"
"github.com/spf13/viper" "github.com/spf13/viper"
"google.golang.org/grpc" "google.golang.org/grpc"
)
import health "google.golang.org/grpc/health/grpc_health_v1" health "google.golang.org/grpc/health/grpc_health_v1"
)
type Server struct { type Server struct {
proto.UnimplementedAuthServer proto.UnimplementedAuthServer
proto.UnimplementedNotifierServer proto.UnimplementedNotifierServer
proto.UnimplementedRealmServer proto.UnimplementedRealmServer
proto.UnimplementedStreamControllerServer
health.UnimplementedHealthServer health.UnimplementedHealthServer
srv *grpc.Server srv *grpc.Server
@ -28,6 +30,7 @@ func NewServer() *Server {
proto.RegisterAuthServer(server.srv, server) proto.RegisterAuthServer(server.srv, server)
proto.RegisterNotifierServer(server.srv, server) proto.RegisterNotifierServer(server.srv, server)
proto.RegisterRealmServer(server.srv, server) proto.RegisterRealmServer(server.srv, server)
proto.RegisterStreamControllerServer(server.srv, server)
health.RegisterHealthServer(server.srv, server) health.RegisterHealthServer(server.srv, server)
reflection.Register(server.srv) reflection.Register(server.srv)

View File

@ -0,0 +1,21 @@
package grpc
import (
"context"
"git.solsynth.dev/hydrogen/dealer/pkg/proto"
"git.solsynth.dev/hydrogen/passport/pkg/internal/services"
)
func (v *Server) EmitStreamEvent(ctx context.Context, request *proto.StreamEventRequest) (*proto.StreamEventResponse, error) {
switch request.GetEvent() {
case "ClientRegister":
// No longer need update user online status
// Based on realtime sever connection status
break
case "ClientUnregister":
// Update user last seen at
_ = services.SetAccountLastSeen(uint(request.GetUserId()))
}
return &proto.StreamEventResponse{}, nil
}