1
0
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:
Milos Gajdos 2019-07-09 16:17:18 +01:00
parent c5fb409760
commit 23cb811f60
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F
5 changed files with 7 additions and 120 deletions

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}

View File

@ -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"
}