Skip to content

Commit e39fb38

Browse files
committed
refactor internal/stack/record and upload with off gocognit linter
1 parent c6e45cd commit e39fb38

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Refactored `internal/stack/record.go` and extract func `record.findFileNameAndPkgPath`
12
* Fixed topic writer infinite reconnections in some cases
23
* Refactored nil on err `internal/grpcwrapper/rawydb/issues.go`, when golangci-lint nilerr enabled
34
* Refactored nil on err `internal/grpcwrapper/rawtopic/describe_topic.go`, when golangci-lint nilerr enabled

internal/stack/record.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,7 @@ func (c call) Record(opts ...recordOption) string {
9797
funcName string
9898
file = c.file
9999
)
100-
if i := strings.LastIndex(file, "/"); i > -1 {
101-
file = file[i+1:]
102-
}
103-
if i := strings.LastIndex(name, "/"); i > -1 {
104-
pkgPath, name = name[:i], name[i+1:]
105-
}
106-
split := strings.Split(name, ".")
100+
file, pkgPath, split := findFileNameAndPkgPath(file, name, pkgPath)
107101
lambdas := make([]string, 0, len(split))
108102
for i := range split {
109103
elem := split[len(split)-i-1]
@@ -171,6 +165,23 @@ func (c call) Record(opts ...recordOption) string {
171165
return buffer.String()
172166
}
173167

168+
// findFileNameAndPkgPath extracts the file name and package path from a string and splits the name into its components.
169+
func findFileNameAndPkgPath(
170+
file string,
171+
name string,
172+
pkgPath string,
173+
) (string, string, []string) {
174+
if i := strings.LastIndex(file, "/"); i > -1 {
175+
file = file[i+1:]
176+
}
177+
if i := strings.LastIndex(name, "/"); i > -1 {
178+
pkgPath, name = name[:i], name[i+1:]
179+
}
180+
split := strings.Split(name, ".")
181+
182+
return file, pkgPath, split
183+
}
184+
174185
func (c call) FunctionID() string {
175186
return c.Record(Lambda(false), FileName(false))
176187
}

0 commit comments

Comments
 (0)