mirror of
https://github.com/go-micro/go-micro.git
synced 2024-12-24 10:07:04 +02:00
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/registry"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -547,23 +546,6 @@ func (r *router) Stop() error {
|
||||
}
|
||||
|
||||
// String prints debugging information about router
|
||||
func (r *router) String() string {
|
||||
sb := &strings.Builder{}
|
||||
|
||||
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()
|
||||
func (r router) String() string {
|
||||
return "router"
|
||||
}
|
||||
|
@ -1,12 +1,9 @@
|
||||
package table
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
// TableOptions specify routing table options
|
||||
@ -230,33 +227,6 @@ func (t *table) Size() int {
|
||||
}
|
||||
|
||||
// String returns debug information
|
||||
func (t *table) String() string {
|
||||
t.RLock()
|
||||
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()
|
||||
func (t table) String() string {
|
||||
return "table"
|
||||
}
|
||||
|
@ -1,12 +1,5 @@
|
||||
package table
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
// LookupPolicy defines query policy
|
||||
type LookupPolicy int
|
||||
|
||||
@ -111,23 +104,5 @@ func (q *query) Options() QueryOptions {
|
||||
|
||||
// String prints routing table query in human readable form
|
||||
func (q query) String() string {
|
||||
// this will help us build routing table string
|
||||
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()
|
||||
return "query"
|
||||
}
|
||||
|
@ -1,11 +1,7 @@
|
||||
package table
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"hash/fnv"
|
||||
"strings"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -44,25 +40,5 @@ func (r *Route) Hash() uint64 {
|
||||
|
||||
// String returns human readable route
|
||||
func (r Route) String() string {
|
||||
// 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"})
|
||||
|
||||
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()
|
||||
return "route"
|
||||
}
|
||||
|
@ -3,10 +3,7 @@ package table
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -125,18 +122,5 @@ func (w *tableWatcher) Stop() {
|
||||
|
||||
// String prints debug information
|
||||
func (w tableWatcher) String() string {
|
||||
sb := &strings.Builder{}
|
||||
|
||||
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()
|
||||
return "watcher"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user