Commit de07543e by 孙龙

新增微服务注册相关

parent 2b2334b1
...@@ -2,7 +2,10 @@ package main ...@@ -2,7 +2,10 @@ package main
import ( import (
"flag" "flag"
"fmt"
"github.com/ichunt2019/cfg/lib"
"ichunt_golang/boot" "ichunt_golang/boot"
"ichunt_golang/util/regist_etcd"
"os" "os"
"os/signal" "os/signal"
"syscall" "syscall"
...@@ -20,10 +23,14 @@ func main(){ ...@@ -20,10 +23,14 @@ func main(){
boot.Init(configPath,logPath) boot.Init(configPath,logPath)
fmt.Println(lib.Instance("proxy").GetString("micro_service_name"))
go func() { go func() {
router.HttpServerRun() router.HttpServerRun()
}() }()
regist_etcd.Init()
quit := make(chan os.Signal) quit := make(chan os.Signal)
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM)
<-quit <-quit
......
# This is base config #服务注册名称
micro_service_name = "golang_common_demo"
#etcd配置信息 etcd服务的ip端口用户密码
[etcd_config]
addrs = [
"192.168.2.232:2379"
]
username = ""
password = ""
#注册到etcd中的ip 端口 权重信息
[etcd_regist]
ip = "192.168.2.246"
port = 60020
weight = 10
[base] [base]
debug_mode="debug" debug_mode="debug"
......
...@@ -4,11 +4,17 @@ go 1.14 ...@@ -4,11 +4,17 @@ go 1.14
require ( require (
github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect github.com/boj/redistore v0.0.0-20180917114910-cd5dcc76aeff // indirect
github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19 github.com/dustin/go-humanize v1.0.0 // indirect
github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19 // indirect
github.com/gin-gonic/gin v1.6.3 github.com/gin-gonic/gin v1.6.3
github.com/gorilla/sessions v1.2.1 // indirect github.com/gorilla/sessions v1.2.1 // indirect
github.com/ichunt2019/cfg v0.0.0-20210225081543-828ee9831d70 github.com/ichunt2019/cfg v0.0.0-20210225081543-828ee9831d70
github.com/ichunt2019/ichunt-micro-registry v1.0.1
github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042 github.com/ichunt2019/lxLog v0.0.0-20210226024426-781becb3c042
github.com/spf13/viper v1.7.1 github.com/spf13/viper v1.7.1
github.com/tidwall/gjson v1.6.8 // indirect github.com/tidwall/gjson v1.6.8 // indirect
google.golang.org/grpc/examples v0.0.0-20210226164526-c949703b4b98 // indirect
sigs.k8s.io/yaml v1.2.0 // indirect
) )
replace google.golang.org/grpc => google.golang.org/grpc v1.26.0
\ No newline at end of file
package regist_etcd
import (
"github.com/ichunt2019/ichunt-micro-registry/registry"
econfig "github.com/ichunt2019/ichunt-micro-registry/config"
_ "github.com/ichunt2019/ichunt-micro-registry/registry/etcd"
"github.com/ichunt2019/cfg/lib"
)
func Init(){
nodes := []*registry.Node{
{
IP: lib.Instance("proxy").GetString("etcd_regist.ip"),
Port: lib.Instance("proxy").GetInt("etcd_regist.port"),
Weight:lib.Instance("proxy").GetInt("etcd_regist.weight"),
},
}
etcdConfig := registry.EtcdConfig{
Address: lib.Instance("proxy").GetStringSlice("etcd_config.addrs"),
Username: lib.Instance("proxy").GetString("etcd_config.username"),
Password:lib.Instance("proxy").GetString("etcd_config.password"),
Path:"/ichuntMicroService/",
}
econfig.Register(lib.Instance("proxy").GetString("micro_service_name"),etcdConfig,nodes)
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment