From b57ebd5c1c57d7f095c7c52aaa4d0cd5c8c13cb2 Mon Sep 17 00:00:00 2001 From: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Wed, 19 May 2021 19:59:46 +0800 Subject: [PATCH] vFormat: use gci instead of customized goimports (#1020) --- format.go | 2 +- infra/vformat/main.go | 8 +++----- transport/internet/headers/http/linkedreadRequest.go | 2 +- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/format.go b/format.go index ed0171462..ea342be63 100644 --- a/format.go +++ b/format.go @@ -1,4 +1,4 @@ package core -//go:generate go install -v github.com/v2fly/tools/cmd/goimports@latest +//go:generate go install -v github.com/daixiang0/gci@latest //go:generate go run ./infra/vformat/ diff --git a/infra/vformat/main.go b/infra/vformat/main.go index 0ac4ce4bf..6e895e59f 100644 --- a/infra/vformat/main.go +++ b/infra/vformat/main.go @@ -3,7 +3,6 @@ package main import ( "fmt" "go/build" - "io/ioutil" "os" "os/exec" "path/filepath" @@ -42,7 +41,7 @@ func GetRuntimeEnv(key string) (string, error) { } var data []byte var runtimeEnv string - data, readErr := ioutil.ReadFile(file) + data, readErr := os.ReadFile(file) if readErr != nil { return "", readErr } @@ -50,7 +49,7 @@ func GetRuntimeEnv(key string) (string, error) { for _, envItem := range envStrings { envItem = strings.TrimSuffix(envItem, "\r") envKeyValue := strings.Split(envItem, "=") - if strings.EqualFold(strings.TrimSpace(envKeyValue[0]), key) { + if len(envKeyValue) == 2 && strings.TrimSpace(envKeyValue[0]) == key { runtimeEnv = strings.TrimSpace(envKeyValue[1]) } } @@ -123,7 +122,7 @@ func main() { suffix = ".exe" } gofmt := "gofmt" + suffix - goimports := "goimports" + suffix + goimports := "gci" + suffix if gofmtPath, err := exec.LookPath(gofmt); err != nil { fmt.Println("Can not find", gofmt, "in system path or current working directory.") @@ -172,7 +171,6 @@ func main() { goimportsArgs := []string{ "-w", - "-r", "-local", "github.com/v2fly/v2ray-core", } diff --git a/transport/internet/headers/http/linkedreadRequest.go b/transport/internet/headers/http/linkedreadRequest.go index 6d750567e..1b7fc3607 100644 --- a/transport/internet/headers/http/linkedreadRequest.go +++ b/transport/internet/headers/http/linkedreadRequest.go @@ -3,7 +3,7 @@ package http import ( "bufio" "net/http" - _ "unsafe" // required to use //go:linkname + _ "unsafe" ) //go:linkname readRequest net/http.readRequest