Browse Source

grpc sample docker run ok

pull/43/head v1.3.1
yedf2 5 years ago
parent
commit
08a5dab5a6
  1. 1
      dtmgrpc/type.go
  2. 2
      examples/base_grpc.go
  3. 27
      helper/docker-compose.dev.yml

1
dtmgrpc/type.go

@ -17,6 +17,7 @@ var clients sync.Map
// GetGrpcConn 1 // GetGrpcConn 1
func GetGrpcConn(grpcServer string) (conn *grpc.ClientConn, rerr error) { func GetGrpcConn(grpcServer string) (conn *grpc.ClientConn, rerr error) {
grpcServer = dtmcli.MayReplaceLocalhost(grpcServer)
v, ok := clients.Load(grpcServer) v, ok := clients.Load(grpcServer)
if !ok { if !ok {
dtmcli.Logf("grpc client connecting %s", grpcServer) dtmcli.Logf("grpc client connecting %s", grpcServer)

2
examples/base_grpc.go

@ -22,7 +22,7 @@ var DtmClient dtmgrpc.DtmClient = nil
// GrpcStartup for grpc // GrpcStartup for grpc
func GrpcStartup() { func GrpcStartup() {
conn, err := grpc.Dial(DtmGrpcServer, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithUnaryInterceptor(dtmgrpc.GrpcClientLog)) conn, err := grpc.Dial(DtmGrpcServer, grpc.WithInsecure(), grpc.WithUnaryInterceptor(dtmgrpc.GrpcClientLog))
dtmcli.FatalIfError(err) dtmcli.FatalIfError(err)
DtmClient = dtmgrpc.NewDtmClient(conn) DtmClient = dtmgrpc.NewDtmClient(conn)
dtmcli.Logf("dtm client inited") dtmcli.Logf("dtm client inited")

27
helper/docker-compose.dev.yml

@ -0,0 +1,27 @@
version: '3.3'
services:
api:
image: golang:1.16.6-alpine3.14
environment:
IS_DOCKER: '1'
GOPROXY: 'https://mirrors.aliyun.com/goproxy/,direct'
ports:
- '8080:8080'
- '58080:58080'
volumes:
- ..:/app/work
command: ['go', 'run', '/app/work/app/main.go', 'dev']
working_dir: /app/work
mysql:
image: 'mysql:5.7'
environment:
MYSQL_ALLOW_EMPTY_PASSWORD: 1
TZ: Asia/shanghai
command:
[
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci',
'--default-time-zone=+8:00',
]
ports:
- '3306:3306'
Loading…
Cancel
Save