You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
511 B
Go
27 lines
511 B
Go
package session
|
|
|
|
import "sync"
|
|
|
|
// Router is used to select remote service address
|
|
type Router struct {
|
|
routes sync.Map
|
|
}
|
|
|
|
func newRouter() *Router {
|
|
return &Router{}
|
|
}
|
|
|
|
// Bind bound an address to remote service
|
|
func (r *Router) Bind(service, address string) {
|
|
r.routes.Store(service, address)
|
|
}
|
|
|
|
// Find finds the address corresponding a remote service
|
|
func (r *Router) Find(service string) (string, bool) {
|
|
v, found := r.routes.Load(service)
|
|
if !found {
|
|
return "", false
|
|
}
|
|
return v.(string), true
|
|
}
|