mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
849 B
39 lines
849 B
8 years ago
|
// Copyright 2013, 2014 Canonical Ltd.
|
||
|
// Licensed under the LGPLv3, see LICENCE file for details.
|
||
|
|
||
|
package errors
|
||
|
|
||
|
import (
|
||
|
"runtime"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
// prefixSize is used internally to trim the user specific path from the
|
||
|
// front of the returned filenames from the runtime call stack.
|
||
|
var prefixSize int
|
||
|
|
||
|
// goPath is the deduced path based on the location of this file as compiled.
|
||
|
var goPath string
|
||
|
|
||
|
func init() {
|
||
|
_, file, _, ok := runtime.Caller(0)
|
||
|
if file == "?" {
|
||
|
return
|
||
|
}
|
||
|
if ok {
|
||
|
// We know that the end of the file should be:
|
||
|
// github.com/juju/errors/path.go
|
||
|
size := len(file)
|
||
|
suffix := len("github.com/juju/errors/path.go")
|
||
|
goPath = file[:size-suffix]
|
||
|
prefixSize = len(goPath)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func trimGoPath(filename string) string {
|
||
|
if strings.HasPrefix(filename, goPath) {
|
||
|
return filename[prefixSize:]
|
||
|
}
|
||
|
return filename
|
||
|
}
|