Removed fmt.Stringer artistry from all roouter and table structs
This commit is contained in:
parent
c5fb409760
commit
23cb811f60
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/micro/go-micro/network/router/table"
|
"github.com/micro/go-micro/network/router/table"
|
||||||
"github.com/micro/go-micro/registry"
|
"github.com/micro/go-micro/registry"
|
||||||
"github.com/olekukonko/tablewriter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -547,23 +546,6 @@ func (r *router) Stop() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String prints debugging information about router
|
// String prints debugging information about router
|
||||||
func (r *router) String() string {
|
func (r router) String() string {
|
||||||
sb := &strings.Builder{}
|
return "router"
|
||||||
|
|
||||||
table := tablewriter.NewWriter(sb)
|
|
||||||
table.SetHeader([]string{"ID", "Address", "Network", "Table", "Status"})
|
|
||||||
|
|
||||||
data := []string{
|
|
||||||
r.opts.ID,
|
|
||||||
r.opts.Address,
|
|
||||||
r.opts.Network,
|
|
||||||
fmt.Sprintf("%d", r.opts.Table.Size()),
|
|
||||||
r.status.Code.String(),
|
|
||||||
}
|
|
||||||
table.Append(data)
|
|
||||||
|
|
||||||
// render table into sb
|
|
||||||
table.Render()
|
|
||||||
|
|
||||||
return sb.String()
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,9 @@
|
|||||||
package table
|
package table
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/olekukonko/tablewriter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// TableOptions specify routing table options
|
// TableOptions specify routing table options
|
||||||
@ -230,33 +227,6 @@ func (t *table) Size() int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// String returns debug information
|
// String returns debug information
|
||||||
func (t *table) String() string {
|
func (t table) String() string {
|
||||||
t.RLock()
|
return "table"
|
||||||
defer t.RUnlock()
|
|
||||||
|
|
||||||
// this will help us build routing table string
|
|
||||||
sb := &strings.Builder{}
|
|
||||||
|
|
||||||
// create nice table printing structure
|
|
||||||
table := tablewriter.NewWriter(sb)
|
|
||||||
table.SetHeader([]string{"Service", "Address", "Gateway", "Network", "Link", "Metric"})
|
|
||||||
|
|
||||||
for _, destRoute := range t.m {
|
|
||||||
for _, route := range destRoute {
|
|
||||||
strRoute := []string{
|
|
||||||
route.Service,
|
|
||||||
route.Address,
|
|
||||||
route.Gateway,
|
|
||||||
route.Network,
|
|
||||||
route.Link,
|
|
||||||
fmt.Sprintf("%d", route.Metric),
|
|
||||||
}
|
|
||||||
table.Append(strRoute)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// render table into sb
|
|
||||||
table.Render()
|
|
||||||
|
|
||||||
return sb.String()
|
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,5 @@
|
|||||||
package table
|
package table
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/olekukonko/tablewriter"
|
|
||||||
)
|
|
||||||
|
|
||||||
// LookupPolicy defines query policy
|
// LookupPolicy defines query policy
|
||||||
type LookupPolicy int
|
type LookupPolicy int
|
||||||
|
|
||||||
@ -111,23 +104,5 @@ func (q *query) Options() QueryOptions {
|
|||||||
|
|
||||||
// String prints routing table query in human readable form
|
// String prints routing table query in human readable form
|
||||||
func (q query) String() string {
|
func (q query) String() string {
|
||||||
// this will help us build routing table string
|
return "query"
|
||||||
sb := &strings.Builder{}
|
|
||||||
|
|
||||||
// create nice table printing structure
|
|
||||||
table := tablewriter.NewWriter(sb)
|
|
||||||
table.SetHeader([]string{"Service", "Gateway", "Network", "Policy"})
|
|
||||||
|
|
||||||
strQuery := []string{
|
|
||||||
q.opts.Service,
|
|
||||||
q.opts.Gateway,
|
|
||||||
q.opts.Network,
|
|
||||||
fmt.Sprintf("%s", q.opts.Policy),
|
|
||||||
}
|
|
||||||
table.Append(strQuery)
|
|
||||||
|
|
||||||
// render table into sb
|
|
||||||
table.Render()
|
|
||||||
|
|
||||||
return sb.String()
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,7 @@
|
|||||||
package table
|
package table
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"hash/fnv"
|
"hash/fnv"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/olekukonko/tablewriter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -44,25 +40,5 @@ func (r *Route) Hash() uint64 {
|
|||||||
|
|
||||||
// String returns human readable route
|
// String returns human readable route
|
||||||
func (r Route) String() string {
|
func (r Route) String() string {
|
||||||
// this will help us build routing table string
|
return "route"
|
||||||
sb := &strings.Builder{}
|
|
||||||
|
|
||||||
// create nice table printing structure
|
|
||||||
table := tablewriter.NewWriter(sb)
|
|
||||||
table.SetHeader([]string{"Service", "Address", "Gateway", "Network", "Link", "Metric"})
|
|
||||||
|
|
||||||
strRoute := []string{
|
|
||||||
r.Service,
|
|
||||||
r.Address,
|
|
||||||
r.Gateway,
|
|
||||||
r.Network,
|
|
||||||
r.Link,
|
|
||||||
fmt.Sprintf("%d", r.Metric),
|
|
||||||
}
|
|
||||||
table.Append(strRoute)
|
|
||||||
|
|
||||||
// render table into sb
|
|
||||||
table.Render()
|
|
||||||
|
|
||||||
return sb.String()
|
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,7 @@ package table
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/olekukonko/tablewriter"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -125,18 +122,5 @@ func (w *tableWatcher) Stop() {
|
|||||||
|
|
||||||
// String prints debug information
|
// String prints debug information
|
||||||
func (w tableWatcher) String() string {
|
func (w tableWatcher) String() string {
|
||||||
sb := &strings.Builder{}
|
return "watcher"
|
||||||
|
|
||||||
table := tablewriter.NewWriter(sb)
|
|
||||||
table.SetHeader([]string{"Service"})
|
|
||||||
|
|
||||||
data := []string{
|
|
||||||
w.opts.Service,
|
|
||||||
}
|
|
||||||
table.Append(data)
|
|
||||||
|
|
||||||
// render table into sb
|
|
||||||
table.Render()
|
|
||||||
|
|
||||||
return sb.String()
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user