mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-06-26 09:25:23 +00:00
Refine errorgen
This commit is contained in:
parent
4130b54579
commit
0650af46f4
|
@ -5,35 +5,41 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
|
"v2ray.com/core/common"
|
||||||
)
|
)
|
||||||
|
|
||||||
func getCurrentPkg() (string, error) {
|
|
||||||
path, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return filepath.Base(path), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
pkg, err := getCurrentPkg()
|
pwd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Failed to get current package: ", err.Error())
|
fmt.Println("can not get current working directory")
|
||||||
return
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
pkg := filepath.Base(pwd)
|
||||||
|
if pkg == "v2ray-core" {
|
||||||
|
pkg = "core"
|
||||||
|
}
|
||||||
|
|
||||||
|
moduleName, gmnErr := common.GetModuleName(pwd)
|
||||||
|
if gmnErr != nil {
|
||||||
|
fmt.Println("can not get module path", gmnErr)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to generate errors.generated.go: %v", err)
|
log.Fatalf("Failed to generate errors.generated.go: %v", err)
|
||||||
return
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
fmt.Fprintln(file, "package", pkg)
|
fmt.Fprintln(file, "package", pkg)
|
||||||
fmt.Fprintln(file, "")
|
fmt.Fprintln(file, "")
|
||||||
fmt.Fprintln(file, "import \"v2ray.com/core/common/errors\"")
|
fmt.Fprintln(file, "import \""+moduleName+"/common/errors\"")
|
||||||
fmt.Fprintln(file, "")
|
fmt.Fprintln(file, "")
|
||||||
fmt.Fprintln(file, "type errPathObjHolder struct {}")
|
fmt.Fprintln(file, "type errPathObjHolder struct{}")
|
||||||
fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }")
|
fmt.Fprintln(file, "")
|
||||||
|
fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error {")
|
||||||
file.Close()
|
fmt.Fprintln(file, " return errors.New(values...).WithPathObj(errPathObjHolder{})")
|
||||||
|
fmt.Fprintln(file, "}")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user