mirror of
https://github.com/bigbeer1/m7sRpc.git
synced 2025-12-24 12:47:53 +08:00
feat(初始化m7sRpc): 初始化m7sRpc
初始化m7sRpc
This commit is contained in:
48
internal/config/config.go
Normal file
48
internal/config/config.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/bigbeer1/m7sRpc/internal/server"
|
||||
"github.com/bigbeer1/m7sRpc/internal/svc"
|
||||
"github.com/bigbeer1/m7sRpc/m7sClient"
|
||||
"github.com/zeromicro/go-zero/core/service"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
. "m7s.live/engine/v4"
|
||||
)
|
||||
|
||||
type RedisConfig struct {
|
||||
zrpc.RpcServerConf
|
||||
|
||||
Mysql struct {
|
||||
DataSource string
|
||||
}
|
||||
|
||||
CacheRedis cache.CacheConf
|
||||
}
|
||||
|
||||
var plugin = InstallPlugin(&RedisConfig{})
|
||||
|
||||
func (c *RedisConfig) OnEvent(event any) {
|
||||
switch event.(type) {
|
||||
case FirstConfig:
|
||||
|
||||
ctx := svc.NewServiceContext(*c)
|
||||
|
||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||
m7sClient.RegisterM7SServer(grpcServer, server.NewM7sServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
})
|
||||
defer s.Stop()
|
||||
|
||||
//rpc log
|
||||
fmt.Println(c.Name, c.ListenOn)
|
||||
s.Start()
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,14 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"github.com/bigbeer1/m7sRpc"
|
||||
"github.com/bigbeer1/m7sRpc/internal/config"
|
||||
)
|
||||
|
||||
type ServiceContext struct {
|
||||
Config m7sRpc.RedisConfig
|
||||
Config config.RedisConfig
|
||||
}
|
||||
|
||||
func NewServiceContext(c m7sRpc.RedisConfig) *ServiceContext {
|
||||
func NewServiceContext(c config.RedisConfig) *ServiceContext {
|
||||
return &ServiceContext{
|
||||
Config: c,
|
||||
}
|
||||
|
||||
52
main.go
52
main.go
@@ -1,53 +1 @@
|
||||
package m7sRpc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/bigbeer1/m7sRpc/internal/server"
|
||||
"github.com/bigbeer1/m7sRpc/internal/svc"
|
||||
"github.com/bigbeer1/m7sRpc/m7sClient"
|
||||
"github.com/zeromicro/go-zero/core/service"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/zrpc"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/reflection"
|
||||
. "m7s.live/engine/v4"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type RedisConfig struct {
|
||||
zrpc.RpcServerConf
|
||||
|
||||
Mysql struct {
|
||||
DataSource string
|
||||
}
|
||||
|
||||
CacheRedis cache.CacheConf
|
||||
}
|
||||
|
||||
var plugin = InstallPlugin(&RedisConfig{})
|
||||
|
||||
func (c *RedisConfig) OnEvent(event any) {
|
||||
switch event.(type) {
|
||||
case FirstConfig:
|
||||
|
||||
ctx := svc.NewServiceContext(*c)
|
||||
|
||||
s := zrpc.MustNewServer(c.RpcServerConf, func(grpcServer *grpc.Server) {
|
||||
m7sClient.RegisterM7SServer(grpcServer, server.NewM7sServer(ctx))
|
||||
|
||||
if c.Mode == service.DevMode || c.Mode == service.TestMode {
|
||||
reflection.Register(grpcServer)
|
||||
}
|
||||
})
|
||||
defer s.Stop()
|
||||
|
||||
//rpc log
|
||||
fmt.Println(c.Name, c.ListenOn)
|
||||
s.Start()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func (c *RedisConfig) Profile(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user