// NewConsulRegister create a new consul register
NewConsulRegister create a new consul register
// NewConsulRegister create a new consul register
func NewConsulRegister(addr string, svc string, port int, tag []string, meta map[string]string) (*ConsulRegister, error) {
	config := api.DefaultConfig()
	config.Address = addr
	client, err := api.NewClient(config)
	if err != nil {
		return nil, err
	}
	ip := localIP()
	deregisterCriticalServiceAfter := time.Duration(1) * time.Minute
	interval := time.Duration(10) * time.Second
	reg := &api.AgentServiceRegistration{
		ID:      fmt.Sprintf("%v-%v-%v", svc, ip, port), 
		Name:    fmt.Sprintf("grpc.health.v1.%v", svc),  
		Tags:    tag,                                    
		Port:    port,                                   
		Address: ip,                                     
		Meta:    meta,
		Check: &api.AgentServiceCheck{ 
			Interval:                       interval.String(),                       间隔
			GRPC:                           fmt.Sprintf("%v:%v/%v", ip, port, svc),  
			DeregisterCriticalServiceAfter: deregisterCriticalServiceAfter.String(), 
		},
	}
	r := &ConsulRegister{
		client:   client,
		register: reg,
	}
	return r, nil
}
func NewConsulRegister ( addr string , svc string , port int , tag [ ] string , meta map [ string ] string ) ( * ConsulRegister , error ) { config := api . DefaultConfig ( ) config . Address = addr client , err := api . NewClient ( config ) if err != nil { return nil , err } ip := localIP ( ) deregisterCriticalServiceAfter := time . Duration ( 1 ) * time . Minute interval := time . Duration ( 10 ) * time . Second reg := & api . AgentServiceRegistration { ID : fmt . Sprintf ( " " , svc , ip , port ) , Name : fmt . Sprintf ( " " , svc ) , Tags : tag , Port : port , Address : ip , Meta : meta , Check : & api . AgentServiceCheck { Interval : interval . String ( ) , GRPC : fmt . Sprintf ( " " , ip , port , svc ) , DeregisterCriticalServiceAfter : deregisterCriticalServiceAfter . String ( ) , } , } r := & ConsulRegister { client : client , register : reg , } return r , nil }
NewConsulRegister create a new consul register
NewConsulRegister create a new consul register
// 服务节点的名称 // 服务名称 // tag，可以为空 // 服务端口 // 服务 IP // 健康检查 // 健康检查间隔 // grpc 支持，执行健康检查的地址，service 会传到 Health.Check 函数中 // 注销时间，相当于过期时间