You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
package discovery
import "log"
// 服务的类型接口
type Service interface {
Name ( ) string
Addr ( ) string
}
// orderService
type OrderService struct {
name string
addr string
}
func ( s OrderService ) Name ( ) string {
return s . name
}
func ( s OrderService ) Addr ( ) string {
return s . addr
}
func ServiceOrder ( addr string ) {
// 一: 初始化orderService
orderService := OrderService {
name : "order" ,
addr : addr ,
}
// 二: 获取RegistrarEtcd
re , err := NewRegistrarEtcd ( [ ] string { "localhost:2379" } ) // redis(6379)
if err != nil {
log . Fatalln ( err )
}
// 三: 将初始化orderService注册到RegistrarEtcd中
if err := re . Register ( orderService ) ; err != nil {
log . Fatalln ( err )
}
// 四:阻塞执行
log . Printf ( "service %s(%s) is running" , orderService . Name ( ) , orderService . Addr ( ) )
select { }
}