Skip to content

Commit 4c04a80

Browse files
authored
Merge pull request #2156 from gocurr/binding_string
hero: optimize *binding'String
2 parents 57f3026 + 7fb0091 commit 4c04a80

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

hero/binding.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"reflect"
66
"sort"
7+
"strconv"
78

89
"github.com/kataras/iris/v12/context"
910
)
@@ -43,15 +44,14 @@ func newStructFieldInput(f reflect.StructField) *Input {
4344

4445
// String returns the string representation of a binding.
4546
func (b *binding) String() string {
46-
index := fmt.Sprintf("%d", b.Input.Index)
47+
var index string
4748
if len(b.Input.StructFieldIndex) > 0 {
48-
for j, i := range b.Input.StructFieldIndex {
49-
if j == 0 {
50-
index = fmt.Sprintf("%d", i)
51-
continue
52-
}
49+
index = strconv.Itoa(b.Input.StructFieldIndex[0])
50+
for _, i := range b.Input.StructFieldIndex[1:] {
5351
index += fmt.Sprintf(".%d", i)
5452
}
53+
} else {
54+
index = strconv.Itoa(b.Input.Index)
5555
}
5656

5757
return fmt.Sprintf("[%s:%s] maps to [%s]", index, b.Input.Type.String(), b.Dependency)

0 commit comments

Comments
 (0)