mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-02 19:19:20 +02:00
vformat supports multi-core processing (#757)
* Feat: vformat supports multi-core processing (#996) Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
This commit is contained in:
parent
a97d45c93a
commit
3554886ce1
|
@ -87,8 +87,7 @@ func (s *Service) Subscribe(name string) *Subscriber {
|
|||
done: done.New(),
|
||||
}
|
||||
s.Lock()
|
||||
subs := append(s.subs[name], sub)
|
||||
s.subs[name] = subs
|
||||
s.subs[name] = append(s.subs[name], sub)
|
||||
s.Unlock()
|
||||
common.Must(s.ctask.Start())
|
||||
return sub
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package core
|
||||
|
||||
//go:generate go install -v golang.org/x/tools/cmd/goimports@latest
|
||||
//go:generate go install -v github.com/daixiang0/gci@latest
|
||||
//go:generate go run ../infra/vformat/main.go -pwd ./..
|
||||
|
|
|
@ -52,7 +52,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])
|
||||
}
|
||||
}
|
||||
|
@ -79,31 +79,31 @@ func GetGOBIN() string {
|
|||
return GOBIN
|
||||
}
|
||||
|
||||
func Run(binary string, args []string) (string, error) {
|
||||
func Run(binary string, args []string) ([]byte, error) {
|
||||
cmd := exec.Command(binary, args...)
|
||||
cmd.Env = append(cmd.Env, os.Environ()...)
|
||||
output, cmdErr := cmd.CombinedOutput()
|
||||
if cmdErr != nil {
|
||||
return "", cmdErr
|
||||
return nil, cmdErr
|
||||
}
|
||||
if len(output) > 0 {
|
||||
return string(output), nil
|
||||
}
|
||||
return "", nil
|
||||
return output, nil
|
||||
}
|
||||
|
||||
func RunMany(binary string, args, files []string) {
|
||||
fmt.Println("Processing...")
|
||||
|
||||
maxTasks := make(chan struct{}, runtime.NumCPU())
|
||||
for _, file := range files {
|
||||
args2 := append(args, file)
|
||||
output, err := Run(binary, args2)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
continue
|
||||
}
|
||||
if len(output) > 0 {
|
||||
fmt.Println(output)
|
||||
}
|
||||
maxTasks <- struct{}{}
|
||||
go func(file string) {
|
||||
output, err := Run(binary, append(args, file))
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
} else if len(output) > 0 {
|
||||
fmt.Println(string(output))
|
||||
}
|
||||
<-maxTasks
|
||||
}(file)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -135,7 +135,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.")
|
||||
|
@ -151,7 +151,7 @@ func main() {
|
|||
goimports = goimportsPath
|
||||
}
|
||||
|
||||
rawFilesSlice := make([]string, 0)
|
||||
rawFilesSlice := make([]string, 0, 1000)
|
||||
walkErr := filepath.Walk(pwd, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
@ -166,7 +166,8 @@ func main() {
|
|||
filename := filepath.Base(path)
|
||||
if strings.HasSuffix(filename, ".go") &&
|
||||
!strings.HasSuffix(filename, ".pb.go") &&
|
||||
!strings.Contains(dir, filepath.Join("testing", "mocks")) {
|
||||
!strings.Contains(dir, filepath.Join("testing", "mocks")) &&
|
||||
!strings.Contains(path, filepath.Join("main", "distro", "all", "all.go")) {
|
||||
rawFilesSlice = append(rawFilesSlice, path)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,8 @@ import (
|
|||
"bufio"
|
||||
"net/http"
|
||||
|
||||
_ "unsafe" // required to use //go:linkname
|
||||
// required to use go:linkname
|
||||
_ "unsafe"
|
||||
)
|
||||
|
||||
//go:linkname readRequest net/http.readRequest
|
||||
|
|
Loading…
Reference in New Issue