Skip to content

Commit

Permalink
❤️ some improve && upgrade go1.18+
Browse files Browse the repository at this point in the history
  • Loading branch information
LockGit committed May 9, 2022
1 parent 4b5682c commit 6ef4680
Show file tree
Hide file tree
Showing 2,076 changed files with 93,948 additions and 348,107 deletions.
22 changes: 19 additions & 3 deletions api/rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@ package rpc

import (
"context"
"github.com/rpcxio/libkv/store"
etcdV3 "github.com/rpcxio/rpcx-etcd/client"
"github.com/sirupsen/logrus"
"github.com/smallnest/rpcx/client"
"gochat/config"
"gochat/proto"
"sync"
"time"
)

var LogicRpcClient client.XClient
Expand All @@ -24,17 +27,30 @@ var RpcLogicObj *RpcLogic

func InitLogicRpcClient() {
once.Do(func() {
d := client.NewEtcdV3Discovery(
etcdConfigOption := &store.Config{
ClientTLS: nil,
TLS: nil,
ConnectionTimeout: time.Duration(config.Conf.Common.CommonEtcd.ConnectionTimeout) * time.Second,
Bucket: "",
PersistConnection: true,
Username: config.Conf.Common.CommonEtcd.UserName,
Password: config.Conf.Common.CommonEtcd.Password,
}
d, err := etcdV3.NewEtcdV3Discovery(
config.Conf.Common.CommonEtcd.BasePath,
config.Conf.Common.CommonEtcd.ServerPathLogic,
[]string{config.Conf.Common.CommonEtcd.Host},
nil,
true,
etcdConfigOption,
)
if err != nil {
logrus.Fatalf("init connect rpc etcd discovery client fail:%s", err.Error())
}
LogicRpcClient = client.NewXClient(config.Conf.Common.CommonEtcd.ServerPathLogic, client.Failtry, client.RandomSelect, d, client.DefaultOption)
RpcLogicObj = new(RpcLogic)
})
if LogicRpcClient == nil {
logrus.Errorf("get logic rpc client nil")
logrus.Fatalf("get logic rpc client nil")
}
}

Expand Down
3 changes: 3 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ type CommonEtcd struct {
BasePath string `mapstructure:"basePath"`
ServerPathLogic string `mapstructure:"serverPathLogic"`
ServerPathConnect string `mapstructure:"serverPathConnect"`
UserName string `mapstructure:"userName"`
Password string `mapstructure:"password"`
ConnectionTimeout int `mapstructure:"connectionTimeout"`
}

type CommonRedis struct {
Expand Down
3 changes: 3 additions & 0 deletions config/dev/common.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ host = "127.0.0.1:2379"
basePath = "/gochat_srv"
serverPathLogic = "LogicRpc"
serverPathConnect = "ConnectRpc"
userName = ""
password = ""
connectionTimeout = 5

[common-redis]
redisAddress = "127.0.0.1:6379"
Expand Down
3 changes: 3 additions & 0 deletions config/prod/common.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ host = "127.0.0.1:2379"
basePath = "/gochat_srv"
serverPathLogic = "LogicRpc"
serverPathConnect = "ConnectRpc"
userName = ""
password = ""
connectionTimeout = 5

[common-redis]
redisAddress = "127.0.0.1:6379"
Expand Down
21 changes: 18 additions & 3 deletions connect/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import (
"errors"
"fmt"
"github.com/rcrowley/go-metrics"
"github.com/rpcxio/libkv/store"
etcdV3 "github.com/rpcxio/rpcx-etcd/client"
"github.com/rpcxio/rpcx-etcd/serverplugin"
"github.com/sirupsen/logrus"
"github.com/smallnest/rpcx/client"
"github.com/smallnest/rpcx/server"
"github.com/smallnest/rpcx/serverplugin"
"gochat/config"
"gochat/proto"
"gochat/tools"
Expand All @@ -29,13 +31,26 @@ type RpcConnect struct {
}

func (c *Connect) InitLogicRpcClient() (err error) {
etcdConfigOption := &store.Config{
ClientTLS: nil,
TLS: nil,
ConnectionTimeout: time.Duration(config.Conf.Common.CommonEtcd.ConnectionTimeout) * time.Second,
Bucket: "",
PersistConnection: true,
Username: config.Conf.Common.CommonEtcd.UserName,
Password: config.Conf.Common.CommonEtcd.Password,
}
once.Do(func() {
d := client.NewEtcdV3Discovery(
d, e := etcdV3.NewEtcdV3Discovery(
config.Conf.Common.CommonEtcd.BasePath,
config.Conf.Common.CommonEtcd.ServerPathLogic,
[]string{config.Conf.Common.CommonEtcd.Host},
nil,
true,
etcdConfigOption,
)
if e != nil {
logrus.Fatalf("init connect rpc etcd discovery client fail:%s", e.Error())
}
logicRpcClient = client.NewXClient(config.Conf.Common.CommonEtcd.ServerPathLogic, client.Failtry, client.RandomSelect, d, client.DefaultOption)
})
if logicRpcClient == nil {
Expand Down
8 changes: 4 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.12
FROM golang:1.18

MAINTAINER Lock <[email protected]>

Expand All @@ -16,12 +16,12 @@ RUN cd /tmp && wget https://github.com/etcd-io/etcd/releases/download/v3.4.3/etc
&& rm -rf etcd-v3.4.3-linux-amd64.tar.gz && rm -rf etcd-v3.4.3-linux-amd64


RUN cd /tmp && wget http://download.redis.io/releases/redis-5.0.4.tar.gz -O redis.tar.gz \
RUN cd /tmp && wget http://download.redis.io/releases/redis-5.0.9.tar.gz -O redis.tar.gz \
&& tar -zxvf redis.tar.gz \
&& cd redis-5.0.4 && make \
&& cd redis-5.0.9 && make \
&& cp ./src/redis-server /bin/ \
&& cp ./src/redis-cli /bin/ \
&& rm -rf redis.tar.gz && rm -rf redis-5.0.4
&& rm -rf redis.tar.gz && rm -rf redis-5.0.9

# default eq dev , you can change this to prod , then will use prod dir config file
ENV RUN_MODE dev
Expand Down
18 changes: 0 additions & 18 deletions go.mod

This file was deleted.

Loading

0 comments on commit 6ef4680

Please sign in to comment.