1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-11-12 23:36:43 -05:00
v2fly/common/errors/errorgen/main.go

40 lines
876 B
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"
2017-12-02 19:04:57 -05:00
)
2018-09-30 12:39:53 -04:00
func getCurrentPkg() (string, error) {
path, err := os.Getwd()
if err != nil {
return "", err
2017-12-02 19:04:57 -05:00
}
2018-09-30 12:39:53 -04:00
return filepath.Base(path), nil
}
2017-12-02 19:04:57 -05:00
2018-09-30 12:39:53 -04:00
func main() {
pkg, err := getCurrentPkg()
if err != nil {
log.Fatal("Failed to get current package: ", err.Error())
return
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)
2018-09-30 12:39:53 -04:00
return
2017-12-02 19:04:57 -05:00
}
2018-09-30 12:39:53 -04:00
fmt.Fprintln(file, "package", pkg)
fmt.Fprintln(file, "")
fmt.Fprintln(file, "import \"v2ray.com/core/common/errors\"")
fmt.Fprintln(file, "")
fmt.Fprintln(file, "type errPathObjHolder struct {}")
fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error { return errors.New(values...).WithPathObj(errPathObjHolder{}) }")
2017-12-02 19:04:57 -05:00
2018-09-30 12:39:53 -04:00
file.Close()
2017-12-02 19:04:57 -05:00
}