Update static router
This commit is contained in:
parent
831dd19240
commit
d0d74bdc83
21
static.go
21
static.go
@ -1,9 +1,18 @@
|
||||
// Package static is a static router which returns the service name as the address + port
|
||||
package static
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
|
||||
"github.com/micro/go-micro/v3/router"
|
||||
)
|
||||
|
||||
var (
|
||||
// DefaulPort is the port to append where nothing is set
|
||||
DefaultPort = 8080
|
||||
)
|
||||
|
||||
// NewRouter returns an initialized static router
|
||||
func NewRouter(opts ...router.Option) router.Router {
|
||||
options := router.DefaultOptions()
|
||||
@ -35,10 +44,18 @@ func (s *static) Table() router.Table {
|
||||
func (s *static) Lookup(service string, opts ...router.LookupOption) ([]router.Route, error) {
|
||||
options := router.NewLookup(opts...)
|
||||
|
||||
_, _ , err := net.SplitHostPort(service)
|
||||
if err == nil {
|
||||
// use the address
|
||||
options.Address = service
|
||||
} else {
|
||||
options.Address = fmt.Sprintf("%s:%d", service, DefaultPort)
|
||||
}
|
||||
|
||||
return []router.Route{
|
||||
router.Route{
|
||||
Address: service,
|
||||
Service: options.Address,
|
||||
Service: service,
|
||||
Address: options.Address,
|
||||
Gateway: options.Gateway,
|
||||
Network: options.Network,
|
||||
Router: options.Router,
|
||||
|
Loading…
x
Reference in New Issue
Block a user