github.com/moqsien/xraycore@v1.8.5/common/errors/errorgen/main.go (about) 1 package main 2 3 import ( 4 "fmt" 5 "os" 6 "path/filepath" 7 ) 8 9 func main() { 10 pwd, err := os.Getwd() 11 if err != nil { 12 fmt.Println("can not get current working directory") 13 os.Exit(1) 14 } 15 pkg := filepath.Base(pwd) 16 if pkg == "xray-core" { 17 pkg = "core" 18 } 19 20 file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0o644) 21 if err != nil { 22 fmt.Printf("Failed to generate errors.generated.go: %v", err) 23 os.Exit(1) 24 } 25 defer file.Close() 26 27 fmt.Fprintf(file, `package %s 28 29 import "github.com/moqsien/xraycore/common/errors" 30 31 type errPathObjHolder struct{} 32 33 func newError(values ...interface{}) *errors.Error { 34 return errors.New(values...).WithPathObj(errPathObjHolder{}) 35 } 36 `, pkg) 37 }