main.go 921 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "os"
  7. "strings"
  8. )
  9. var (
  10. pkg = flag.String("pkg", "", "Target package")
  11. path = flag.String("path", "", "Path")
  12. )
  13. func main() {
  14. flag.Parse()
  15. if len(*pkg) == 0 {
  16. panic("Package is not specified.")
  17. }
  18. if len(*path) == 0 {
  19. panic("Path is not specified.")
  20. }
  21. paths := strings.Split(*path, ",")
  22. for i := range paths {
  23. paths[i] = "\"" + paths[i] + "\""
  24. }
  25. pathStr := strings.Join(paths, ", ")
  26. file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
  27. if err != nil {
  28. log.Fatalf("Failed to generate errors.generated.go: %v", err)
  29. }
  30. defer file.Close()
  31. fmt.Fprintln(file, "package", *pkg)
  32. fmt.Fprintln(file, "")
  33. fmt.Fprintln(file, "import \"v2ray.com/core/common/errors\"")
  34. fmt.Fprintln(file, "")
  35. fmt.Fprintln(file, "func newError(values ...interface{}) *errors.Error { return newError(values...).Path("+pathStr+") }")
  36. }