24 lines
418 B
Go
24 lines
418 B
Go
package routes
|
|
|
|
import (
|
|
"regexp"
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
func PathOf() string {
|
|
_, file, _, _ := runtime.Caller(1)
|
|
idx := strings.Index(file, "routes/")
|
|
path := file[idx+len("routes"):]
|
|
path = strings.TrimSuffix(path, ".go")
|
|
|
|
if strings.HasSuffix(path, "/index") {
|
|
path = strings.TrimSuffix(path, "index")
|
|
}
|
|
|
|
re := regexp.MustCompile(`param_(\w+)`)
|
|
path = re.ReplaceAllString(path, ":$1")
|
|
|
|
return path
|
|
}
|