1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 18:17:52 -05:00
v2fly/common/errors/errorgen/main.go

38 lines
710 B
Go
Raw Normal View History

2017-12-02 19:04:57 -05:00
package main
import (
"fmt"
"os"
2018-09-30 12:39:53 -04:00
"path/filepath"
2017-12-02 19:04:57 -05:00
)
2020-10-04 00:39:11 -04:00
func main() {
pwd, err := os.Getwd()
2018-09-30 12:39:53 -04:00
if err != nil {
2020-10-04 00:39:11 -04:00
fmt.Println("can not get current working directory")
os.Exit(1)
}
pkg := filepath.Base(pwd)
if pkg == "v2ray-core" {
pkg = "core"
2017-12-02 19:04:57 -05:00
}
2021-05-19 17:28:52 -04:00
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0o644)
2017-12-02 19:04:57 -05:00
if err != nil {
2021-03-24 03:18:07 -04:00
fmt.Printf("Failed to generate errors.generated.go: %v", err)
2020-10-04 00:39:11 -04:00
os.Exit(1)
2017-12-02 19:04:57 -05:00
}
2020-10-04 00:39:11 -04:00
defer file.Close()
2017-12-02 19:04:57 -05:00
2021-03-24 03:18:07 -04:00
fmt.Fprintf(file, `package %s
import "github.com/v2fly/v2ray-core/v4/common/errors"
type errPathObjHolder struct{}
func newError(values ...interface{}) *errors.Error {
return errors.New(values...).WithPathObj(errPathObjHolder{})
}
`, pkg)
2017-12-02 19:04:57 -05:00
}