23 lines
319 B
Go
23 lines
319 B
Go
package routes
|
|
|
|
import (
|
|
"runtime"
|
|
"strings"
|
|
)
|
|
|
|
func PathOf() string {
|
|
_, file, _, _ := runtime.Caller(1)
|
|
|
|
// 取 routes/ 之後的部分
|
|
idx := strings.Index(file, "routes/")
|
|
if idx == -1 {
|
|
return "/"
|
|
}
|
|
path := file[idx+len("routes"):]
|
|
|
|
// 去掉 .go
|
|
path = strings.TrimSuffix(path, ".go")
|
|
|
|
return path
|
|
}
|