feat(初始化m7sRpc): 初始化m7sRpc

初始化m7sRpc
This commit is contained in:
dabenxiong
2022-12-08 15:48:25 +08:00
parent c58c21105f
commit 9a291e0883
3 changed files with 51 additions and 55 deletions

48
internal/config/config.go Normal file
View 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()
}
}

View File

@@ -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
View File

@@ -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) {
}