Skip to content
This repository was archived by the owner on Nov 21, 2023. It is now read-only.

Commit b73e84c

Browse files
Merge pull request #15 from goinsane/develop
v1.2.3
2 parents cab6269 + ecf1f57 commit b73e84c

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

erf.go

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ func (e *Erf) Fmt() string {
163163
return e.format
164164
}
165165

166-
// Len returns the length of arguments.
167-
func (e *Erf) Len() int {
168-
return len(e.args)
169-
}
170-
171166
// Arg returns an argument value on the given index. It panics if index is out of range.
172167
func (e *Erf) Arg(index int) interface{} {
173168
if index < 0 || index >= len(e.args) {
@@ -186,6 +181,11 @@ func (e *Erf) Args() []interface{} {
186181
return result
187182
}
188183

184+
// Len returns the length of all arguments.
185+
func (e *Erf) Len() int {
186+
return len(e.args)
187+
}
188+
189189
// Attach attaches tags to arguments, if arguments are given.
190190
// If tag is "", it passes attaching tag to corresponding argument.
191191
// It panics for given errors:
@@ -225,21 +225,25 @@ func (e *Erf) Attach2(tags ...string) error {
225225
return e.Attach(tags...)
226226
}
227227

228-
// TagsLen returns the length of tags.
229-
func (e *Erf) TagsLen() int {
230-
return len(e.tags)
231-
}
232-
233228
// Tag returns an argument value on the given tag. It returns nil if tag is not found.
234229
func (e *Erf) Tag(tag string) interface{} {
230+
index := e.TagIndex(tag)
231+
if index < 0 {
232+
return nil
233+
}
234+
return e.args[index]
235+
}
236+
237+
// TagIndex returns index of an argument on the given tag. It returns -1 if tag is not found.
238+
func (e *Erf) TagIndex(tag string) int {
235239
index := -1
236240
if idx, ok := e.tagIndexes[tag]; ok {
237241
index = idx
238242
}
239243
if index < 0 || index >= len(e.args) {
240-
return nil
244+
return -1
241245
}
242-
return e.args[index]
246+
return index
243247
}
244248

245249
// Tags returns all tags sequentially. It returns nil if tags are not attached.
@@ -252,6 +256,11 @@ func (e *Erf) Tags() []string {
252256
return result
253257
}
254258

259+
// TagsLen returns the length of all tags.
260+
func (e *Erf) TagsLen() int {
261+
return len(e.tags)
262+
}
263+
255264
// PC returns all program counters.
256265
func (e *Erf) PC() []uintptr {
257266
result := make([]uintptr, len(e.pc))

stack.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ func (t *StackTrace) PC() []uintptr {
157157
return result
158158
}
159159

160-
// Len returns the length of the StackCaller slice.
161-
func (t *StackTrace) Len() int {
162-
return len(t.callers)
163-
}
164-
165160
// Caller returns a StackCaller on the given index. It panics if index is out of range.
166161
func (t *StackTrace) Caller(index int) StackCaller {
167-
if index < 0 || index >= t.Len() {
162+
if index < 0 || index >= len(t.callers) {
168163
panic("index out of range")
169164
}
170165
return t.callers[index]
171166
}
167+
168+
// Len returns the length of the length of all Caller's.
169+
func (t *StackTrace) Len() int {
170+
return len(t.callers)
171+
}

0 commit comments

Comments
 (0)