1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2025-01-06 17:36:40 -05:00
v2fly/common/errors/errorgen/main.go

46 lines
1.0 KiB
Go
Raw Normal View History

2017-12-02 19:04:57 -05:00
package main
import (
"fmt"
"log"
"os"
2018-09-30 12:39:53 -04:00
"path/filepath"
2020-10-04 00:39:11 -04:00
"v2ray.com/core/common"
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
}
2020-10-04 00:39:11 -04:00
moduleName, gmnErr := common.GetModuleName(pwd)
if gmnErr != nil {
fmt.Println("can not get module path", gmnErr)
os.Exit(1)
2017-12-02 19:04:57 -05:00
}
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
if err != nil {
log.Fatalf("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
2018-09-30 12:39:53 -04:00
fmt.Fprintln(file, "package", pkg)
fmt.Fprintln(file, "")
2020-10-04 00:39:11 -04:00
fmt.Fprintln(file, "import \""+moduleName+"/common/errors\"")
2018-09-30 12:39:53 -04:00
fmt.Fprintln(file, "")
2020-10-04 00:39:11 -04:00
fmt.Fprintln(file, "type errPathObjHolder struct{}")
fmt.Fprintln(file, "")
fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error {")
fmt.Fprintln(file, " return errors.New(values...).WithPathObj(errPathObjHolder{})")
fmt.Fprintln(file, "}")
2017-12-02 19:04:57 -05:00
}