|
|
@@ -1,6 +1,7 @@
|
|
|
package main
|
|
|
|
|
|
import (
|
|
|
+ "errors"
|
|
|
"flag"
|
|
|
"fmt"
|
|
|
"go/build"
|
|
|
@@ -22,7 +23,7 @@ var directory = flag.String("pwd", "", "Working directory of Xray vprotogen.")
|
|
|
func envFile() (string, error) {
|
|
|
if file := os.Getenv("GOENV"); file != "" {
|
|
|
if file == "off" {
|
|
|
- return "", fmt.Errorf("GOENV=off")
|
|
|
+ return "", errors.New("GOENV=off")
|
|
|
}
|
|
|
return file, nil
|
|
|
}
|
|
|
@@ -31,7 +32,7 @@ func envFile() (string, error) {
|
|
|
return "", err
|
|
|
}
|
|
|
if dir == "" {
|
|
|
- return "", fmt.Errorf("missing user-config dir")
|
|
|
+ return "", errors.New("missing user-config dir")
|
|
|
}
|
|
|
return filepath.Join(dir, "go", "env"), nil
|
|
|
}
|
|
|
@@ -44,7 +45,7 @@ func GetRuntimeEnv(key string) (string, error) {
|
|
|
return "", err
|
|
|
}
|
|
|
if file == "" {
|
|
|
- return "", fmt.Errorf("missing runtime env file")
|
|
|
+ return "", errors.New("missing runtime env file")
|
|
|
}
|
|
|
var data []byte
|
|
|
var runtimeEnv string
|
|
|
@@ -101,12 +102,12 @@ Download %s v%s or later from https://github.com/protocolbuffers/protobuf/releas
|
|
|
func getProjectProtocVersion(url string) (string, error) {
|
|
|
resp, err := http.Get(url)
|
|
|
if err != nil {
|
|
|
- return "", fmt.Errorf("can not get the version of protobuf used in xray project")
|
|
|
+ return "", errors.New("can not get the version of protobuf used in xray project")
|
|
|
}
|
|
|
defer resp.Body.Close()
|
|
|
body, err := io.ReadAll(resp.Body)
|
|
|
if err != nil {
|
|
|
- return "", fmt.Errorf("can not read from body")
|
|
|
+ return "", errors.New("can not read from body")
|
|
|
}
|
|
|
versionRegexp := regexp.MustCompile(`\/\/\s*protoc\s*v\d+\.(\d+\.\d+)`)
|
|
|
matched := versionRegexp.FindStringSubmatch(string(body))
|