2020-11-25 11:01:53 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
"path/filepath"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
pwd, err := os.Getwd()
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println("can not get current working directory")
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
pkg := filepath.Base(pwd)
|
|
|
|
if pkg == "xray-core" {
|
|
|
|
pkg = "core"
|
|
|
|
}
|
|
|
|
|
2021-10-19 16:57:14 +00:00
|
|
|
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0o644)
|
2020-11-25 11:01:53 +00:00
|
|
|
if err != nil {
|
2021-09-20 05:51:55 +00:00
|
|
|
fmt.Printf("Failed to generate errors.generated.go: %v", err)
|
2020-11-25 11:01:53 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
defer file.Close()
|
|
|
|
|
2021-09-20 05:51:55 +00:00
|
|
|
fmt.Fprintf(file, `package %s
|
|
|
|
|
|
|
|
import "github.com/xtls/xray-core/common/errors"
|
|
|
|
|
|
|
|
type errPathObjHolder struct{}
|
|
|
|
|
|
|
|
func newError(values ...interface{}) *errors.Error {
|
|
|
|
return errors.New(values...).WithPathObj(errPathObjHolder{})
|
|
|
|
}
|
|
|
|
`, pkg)
|
2020-11-25 11:01:53 +00:00
|
|
|
}
|