-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.go
More file actions
46 lines (41 loc) · 766 Bytes
/
Copy pathutils.go
File metadata and controls
46 lines (41 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package di
import (
"bytes"
"errors"
"fmt"
"reflect"
"runtime"
"strings"
)
func trimAllPrefixByte(s string, b byte) string {
for {
index := strings.IndexByte(s, b)
if index >= 0 {
s = s[index+1:]
} else {
break
}
}
return s
}
func functionName(val reflect.Value) string {
name := runtime.FuncForPC(val.Pointer()).Name()
name = trimAllPrefixByte(name, '/')
name = strings.TrimSuffix(name, "-fm")
return name
}
type providerErrors struct {
buf bytes.Buffer
}
func (p *providerErrors) Append(name string, err error) {
if p.buf.Len() > 0 {
fmt.Fprintln(&p.buf)
}
fmt.Fprintf(&p.buf, "%s: %s", name, err.Error())
}
func (p *providerErrors) ToError() error {
if p.buf.Len() > 0 {
return errors.New(p.buf.String())
}
return nil
}