From 5a4e8fea8113b38b08bd23a179bd775d33ce00e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Wed, 15 Mar 2023 14:56:06 +0800 Subject: [PATCH] Fix lint --- experimental/libbox/config.go | 2 ++ experimental/libbox/iterator.go | 2 ++ experimental/libbox/log.go | 54 ------------------------------- experimental/libbox/memory.go | 2 ++ experimental/libbox/platform.go | 2 ++ experimental/libbox/pprof.go | 2 +- experimental/libbox/pprof_stub.go | 21 ------------ experimental/libbox/service.go | 2 ++ experimental/libbox/setup.go | 2 ++ experimental/libbox/tun.go | 2 ++ 10 files changed, 15 insertions(+), 76 deletions(-) delete mode 100644 experimental/libbox/log.go delete mode 100644 experimental/libbox/pprof_stub.go diff --git a/experimental/libbox/config.go b/experimental/libbox/config.go index 253f72c6..8a228e8c 100644 --- a/experimental/libbox/config.go +++ b/experimental/libbox/config.go @@ -1,3 +1,5 @@ +//go:build linux || darwin + package libbox import ( diff --git a/experimental/libbox/iterator.go b/experimental/libbox/iterator.go index e23e2a7f..a11133be 100644 --- a/experimental/libbox/iterator.go +++ b/experimental/libbox/iterator.go @@ -1,3 +1,5 @@ +//go:build linux || darwin + package libbox import "github.com/sagernet/sing/common" diff --git a/experimental/libbox/log.go b/experimental/libbox/log.go deleted file mode 100644 index 07190773..00000000 --- a/experimental/libbox/log.go +++ /dev/null @@ -1,54 +0,0 @@ -package libbox - -import ( - "bufio" - "log" - "os" -) - -type StandardOutput interface { - WriteOutput(message string) - WriteErrorOutput(message string) -} - -func SetOutput(output StandardOutput) { - log.SetOutput(logWriter{output}) - pipeIn, pipeOut, err := os.Pipe() - if err != nil { - panic(err) - } - os.Stdout = os.NewFile(pipeOut.Fd(), "stdout") - go lineLog(pipeIn, output.WriteOutput) - - pipeIn, pipeOut, err = os.Pipe() - if err != nil { - panic(err) - } - os.Stderr = os.NewFile(pipeOut.Fd(), "srderr") - go lineLog(pipeIn, output.WriteErrorOutput) -} - -type logWriter struct { - output StandardOutput -} - -func (w logWriter) Write(p []byte) (n int, err error) { - w.output.WriteOutput(string(p)) - return len(p), nil -} - -func lineLog(f *os.File, output func(string)) { - const logSize = 1024 // matches android/log.h. - r := bufio.NewReaderSize(f, logSize) - for { - line, _, err := r.ReadLine() - str := string(line) - if err != nil { - str += " " + err.Error() - } - output(str) - if err != nil { - break - } - } -} diff --git a/experimental/libbox/memory.go b/experimental/libbox/memory.go index 01bf48a9..c3092b0e 100644 --- a/experimental/libbox/memory.go +++ b/experimental/libbox/memory.go @@ -1,3 +1,5 @@ +//go:build darwin + package libbox import "runtime/debug" diff --git a/experimental/libbox/platform.go b/experimental/libbox/platform.go index 09195525..5c8bb0ec 100644 --- a/experimental/libbox/platform.go +++ b/experimental/libbox/platform.go @@ -1,3 +1,5 @@ +//go:build linux || darwin + package libbox import "github.com/sagernet/sing-box/option" diff --git a/experimental/libbox/pprof.go b/experimental/libbox/pprof.go index 86cf3b52..c451dce0 100644 --- a/experimental/libbox/pprof.go +++ b/experimental/libbox/pprof.go @@ -1,4 +1,4 @@ -//go:build debug +//go:build linux || darwin package libbox diff --git a/experimental/libbox/pprof_stub.go b/experimental/libbox/pprof_stub.go deleted file mode 100644 index 580d1ba9..00000000 --- a/experimental/libbox/pprof_stub.go +++ /dev/null @@ -1,21 +0,0 @@ -//go:build !debug - -package libbox - -import ( - "os" -) - -type PProfServer struct{} - -func NewPProfServer(port int) *PProfServer { - return &PProfServer{} -} - -func (s *PProfServer) Start() error { - return os.ErrInvalid -} - -func (s *PProfServer) Close() error { - return os.ErrInvalid -} diff --git a/experimental/libbox/service.go b/experimental/libbox/service.go index e1b7ff88..891d21ab 100644 --- a/experimental/libbox/service.go +++ b/experimental/libbox/service.go @@ -1,3 +1,5 @@ +//go:build linux || darwin + package libbox import ( diff --git a/experimental/libbox/setup.go b/experimental/libbox/setup.go index 97c7e581..222f9363 100644 --- a/experimental/libbox/setup.go +++ b/experimental/libbox/setup.go @@ -1,3 +1,5 @@ +//go:build linux || darwin + package libbox import ( diff --git a/experimental/libbox/tun.go b/experimental/libbox/tun.go index e7db249c..bf8450c9 100644 --- a/experimental/libbox/tun.go +++ b/experimental/libbox/tun.go @@ -1,3 +1,5 @@ +//go:build linux || darwin + package libbox import (