From 8da55410def30e70e27220d0901abbf795455367 Mon Sep 17 00:00:00 2001 From: 9seconds Date: Sat, 19 Mar 2022 14:12:14 +0300 Subject: [PATCH] Run gofumpt --- Makefile | 10 +++++++++- proxy/middle.go | 3 ++- stats/stats_prometheus.go | 3 ++- telegram/base.go | 6 ++++-- telegram/direct.go | 3 ++- telegram/middle.go | 3 ++- utils/init_tcp.go | 2 +- wrappers/stream/blockcipher.go | 3 ++- wrappers/stream/conn.go | 3 ++- wrappers/stream/ctx.go | 3 ++- wrappers/stream/mtproto_cipher.go | 6 ++++-- wrappers/stream/obfuscated2.go | 3 ++- 12 files changed, 34 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 7a9fa1e..2e3dcef 100644 --- a/Makefile +++ b/Makefile @@ -73,8 +73,12 @@ docker: doc: @$(GOTOOL) godoc -http 0.0.0.0:10000 +.PHONY: fmt +fmt: + @$(GOTOOL) gofumpt -w -extra "$(ROOT_DIR)" + .PHONY: install-tools -install-tools: install-tools-lint install-tools-godoc +install-tools: install-tools-lint install-tools-godoc install-tools-gofumpt .PHONY: install-tools-lint install-tools-lint: @@ -87,6 +91,10 @@ install-tools-godoc: @mkdir -p "$(GOBIN)" || true && \ $(GOTOOL) go get -u golang.org/x/tools/cmd/godoc +.PHONY: install-tools-gofumpt +install-tools-gofumpt: .bin + @$(GOTOOL) go install mvdan.cc/gofumpt@latest + .PHONY: update-deps upgrade-deps: $go get -u && go mod tidy diff --git a/proxy/middle.go b/proxy/middle.go index 7f56991..b806e43 100644 --- a/proxy/middle.go +++ b/proxy/middle.go @@ -44,7 +44,8 @@ func middleConnection(request *protocol.TelegramRequest) { func middlePipe(dst conntypes.PacketAckWriteCloser, src conntypes.PacketAckReadCloser, wg *sync.WaitGroup, - logger *zap.SugaredLogger) { + logger *zap.SugaredLogger, +) { defer func() { dst.Close() src.Close() diff --git a/stats/stats_prometheus.go b/stats/stats_prometheus.go index 687c635..adb46d8 100644 --- a/stats/stats_prometheus.go +++ b/stats/stats_prometheus.go @@ -39,7 +39,8 @@ func (s *statsPrometheus) ClientDisconnected(connectionType conntypes.Connection func (s *statsPrometheus) changeConnections(connectionType conntypes.ConnectionType, addr *net.TCPAddr, - increment float64) { + increment float64, +) { labels := [...]string{ "intermediate", "ipv4", diff --git a/telegram/base.go b/telegram/base.go index 4a6c383..67f4c3f 100644 --- a/telegram/base.go +++ b/telegram/base.go @@ -28,7 +28,8 @@ func (b *baseTelegram) Secret() []byte { } func (b *baseTelegram) dial(dc conntypes.DC, - protocol conntypes.ConnectionProtocol) (conntypes.StreamReadWriteCloser, error) { + protocol conntypes.ConnectionProtocol, +) (conntypes.StreamReadWriteCloser, error) { for _, addr := range b.getAddresses(dc, protocol) { conn, err := b.dialer.Dial("tcp", addr) if err != nil { @@ -74,7 +75,8 @@ func (b *baseTelegram) getAddresses(dc conntypes.DC, protocol conntypes.Connecti } func (b *baseTelegram) chooseAddress(addresses map[conntypes.DC][]string, - dc, defaultDC conntypes.DC) string { + dc, defaultDC conntypes.DC, +) string { addrs, ok := addresses[dc] if !ok { addrs = addresses[defaultDC] diff --git a/telegram/direct.go b/telegram/direct.go index 5a7183c..34a8bd6 100644 --- a/telegram/direct.go +++ b/telegram/direct.go @@ -29,7 +29,8 @@ type directTelegram struct { } func (d *directTelegram) Dial(dc conntypes.DC, - protocol conntypes.ConnectionProtocol) (conntypes.StreamReadWriteCloser, error) { + protocol conntypes.ConnectionProtocol, +) (conntypes.StreamReadWriteCloser, error) { switch { case dc < 0: dc = -dc diff --git a/telegram/middle.go b/telegram/middle.go index 3683f4d..556082f 100644 --- a/telegram/middle.go +++ b/telegram/middle.go @@ -63,7 +63,8 @@ func (m *middleTelegram) backgroundUpdate() { } func (m *middleTelegram) Dial(dc conntypes.DC, - protocol conntypes.ConnectionProtocol) (conntypes.StreamReadWriteCloser, error) { + protocol conntypes.ConnectionProtocol, +) (conntypes.StreamReadWriteCloser, error) { if dc == 0 { dc = conntypes.DCDefaultIdx } diff --git a/utils/init_tcp.go b/utils/init_tcp.go index 2152759..69dc67d 100644 --- a/utils/init_tcp.go +++ b/utils/init_tcp.go @@ -5,7 +5,7 @@ import ( "net" ) -func InitTCP(conn net.Conn, readBufferSize int, writeBufferSize int) error { +func InitTCP(conn net.Conn, readBufferSize, writeBufferSize int) error { tcpConn := conn.(*net.TCPConn) // nolint: forcetypeassert if err := tcpConn.SetNoDelay(true); err != nil { diff --git a/wrappers/stream/blockcipher.go b/wrappers/stream/blockcipher.go index 9423d65..19582c8 100644 --- a/wrappers/stream/blockcipher.go +++ b/wrappers/stream/blockcipher.go @@ -70,7 +70,8 @@ func (w *wrapperBlockCipher) RemoteAddr() *net.TCPAddr { } func newBlockCipher(parent conntypes.StreamReadWriteCloser, - encryptor, decryptor cipher.BlockMode) conntypes.StreamReadWriteCloser { + encryptor, decryptor cipher.BlockMode, +) conntypes.StreamReadWriteCloser { cipher := &wrapperBlockCipher{ parent: parent, encryptor: encryptor, diff --git a/wrappers/stream/conn.go b/wrappers/stream/conn.go index f1056d3..86b30b7 100644 --- a/wrappers/stream/conn.go +++ b/wrappers/stream/conn.go @@ -91,7 +91,8 @@ func (w *wrapperConn) RemoteAddr() *net.TCPAddr { func newConn(parent net.Conn, connID conntypes.ConnID, - purpose connPurpose) conntypes.StreamReadWriteCloser { + purpose connPurpose, +) conntypes.StreamReadWriteCloser { localAddr := *parent.LocalAddr().(*net.TCPAddr) if parent.RemoteAddr().(*net.TCPAddr).IP.To4() != nil { diff --git a/wrappers/stream/ctx.go b/wrappers/stream/ctx.go index e948d2c..9a6bb5b 100644 --- a/wrappers/stream/ctx.go +++ b/wrappers/stream/ctx.go @@ -84,7 +84,8 @@ func (w *wrapperCtx) RemoteAddr() *net.TCPAddr { func NewCtx(ctx context.Context, cancel context.CancelFunc, - parent conntypes.StreamReadWriteCloser) conntypes.StreamReadWriteCloser { + parent conntypes.StreamReadWriteCloser, +) conntypes.StreamReadWriteCloser { return &wrapperCtx{ parent: parent, ctx: ctx, diff --git a/wrappers/stream/mtproto_cipher.go b/wrappers/stream/mtproto_cipher.go index 5a59f7c..7e28ba8 100644 --- a/wrappers/stream/mtproto_cipher.go +++ b/wrappers/stream/mtproto_cipher.go @@ -26,7 +26,8 @@ var mtprotoEmptyIP = [4]byte{0x00, 0x00, 0x00, 0x00} func NewMiddleProxyCipher(parent conntypes.StreamReadWriteCloser, req *rpc.NonceRequest, resp *rpc.NonceResponse, - secret []byte) conntypes.StreamReadWriteCloser { + secret []byte, +) conntypes.StreamReadWriteCloser { localAddr := parent.LocalAddr() remoteAddr := parent.RemoteAddr() @@ -53,7 +54,8 @@ func mtprotoDeriveKeys(purpose mtprotoCipherPurpose, req *rpc.NonceRequest, resp *rpc.NonceResponse, client, remote *net.TCPAddr, - secret []byte) ([]byte, []byte) { + secret []byte, +) ([]byte, []byte) { message := bytes.Buffer{} message.Write(resp.Nonce) diff --git a/wrappers/stream/obfuscated2.go b/wrappers/stream/obfuscated2.go index 6e7cc8e..690cef9 100644 --- a/wrappers/stream/obfuscated2.go +++ b/wrappers/stream/obfuscated2.go @@ -84,7 +84,8 @@ func (w *wrapperObfuscated2) Close() error { } func NewObfuscated2(socket conntypes.StreamReadWriteCloser, - encryptor, decryptor cipher.Stream) conntypes.StreamReadWriteCloser { + encryptor, decryptor cipher.Stream, +) conntypes.StreamReadWriteCloser { return &wrapperObfuscated2{ parent: socket, encryptor: encryptor,