mirror of https://github.com/hashicorp/consul
43 lines
651 B
Go
43 lines
651 B
Go
|
// Copyright (c) HashiCorp, Inc.
|
||
|
// SPDX-License-Identifier: MPL-2.0
|
||
|
|
||
|
package retry
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
"fmt"
|
||
|
"runtime"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func dedup(a []string) string {
|
||
|
if len(a) == 0 {
|
||
|
return ""
|
||
|
}
|
||
|
seen := map[string]struct{}{}
|
||
|
var b bytes.Buffer
|
||
|
for _, s := range a {
|
||
|
if _, ok := seen[s]; ok {
|
||
|
continue
|
||
|
}
|
||
|
seen[s] = struct{}{}
|
||
|
b.WriteString(s)
|
||
|
b.WriteRune('\n')
|
||
|
}
|
||
|
return b.String()
|
||
|
}
|
||
|
|
||
|
func decorate(s string) string {
|
||
|
_, file, line, ok := runtime.Caller(3)
|
||
|
if ok {
|
||
|
n := strings.LastIndex(file, "/")
|
||
|
if n >= 0 {
|
||
|
file = file[n+1:]
|
||
|
}
|
||
|
} else {
|
||
|
file = "???"
|
||
|
line = 1
|
||
|
}
|
||
|
return fmt.Sprintf("%s:%d: %s", file, line, s)
|
||
|
}
|