1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-23 02:26:49 -05:00
v2fly/tools/generrorgen/main.go

45 lines
923 B
Go
Raw Normal View History

2017-04-08 18:54:23 -04:00
package main
import (
"flag"
"fmt"
"log"
"os"
"strings"
)
var (
pkg = flag.String("pkg", "", "Target package")
path = flag.String("path", "", "Path")
)
func main() {
flag.Parse()
if len(*pkg) == 0 {
panic("Package is not specified.")
}
if len(*path) == 0 {
panic("Path is not specified.")
}
paths := strings.Split(*path, ",")
for i := range paths {
paths[i] = "\"" + paths[i] + "\""
}
pathStr := strings.Join(paths, ", ")
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)
}
defer file.Close()
fmt.Fprintln(file, "package", *pkg)
fmt.Fprintln(file, "")
fmt.Fprintln(file, "import \"v2ray.com/core/common/errors\"")
fmt.Fprintln(file, "")
2017-04-29 16:23:53 -04:00
fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error { return errors.New(values...).Path("+pathStr+") }")
2017-04-08 18:54:23 -04:00
}