Skip to content

Commit

Permalink
Style: format code by gofumpt (XTLS#761)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuhan6665 authored Oct 19, 2021
1 parent d77be80 commit e286cdc
Show file tree
Hide file tree
Showing 111 changed files with 297 additions and 295 deletions.
4 changes: 1 addition & 3 deletions app/dispatcher/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ import (
"github.com/xtls/xray-core/transport/pipe"
)

var (
errSniffingTimeout = newError("timeout on sniffing")
)
var errSniffingTimeout = newError("timeout on sniffing")

type cachedReader struct {
sync.Mutex
Expand Down
3 changes: 1 addition & 2 deletions app/dns/dns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ import (
"github.com/xtls/xray-core/testing/servers/udp"
)

type staticHandler struct {
}
type staticHandler struct{}

func (*staticHandler) ServeDNS(w dns.ResponseWriter, r *dns.Msg) {
ans := new(dns.Msg)
Expand Down
4 changes: 1 addition & 3 deletions app/dns/dnscommon.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ func isNewer(baseRec *IPRecord, newRec *IPRecord) bool {
return baseRec.Expire.Before(newRec.Expire)
}

var (
errRecordNotFound = errors.New("record not found")
)
var errRecordNotFound = errors.New("record not found")

type dnsRequest struct {
reqType dnsmessage.Type
Expand Down
20 changes: 14 additions & 6 deletions app/dns/dnscommon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,28 @@ func Test_parseResponse(t *testing.T) {
want *IPRecord
wantErr bool
}{
{"empty",
{
"empty",
&IPRecord{0, []net.Address(nil), time.Time{}, dnsmessage.RCodeSuccess},
false,
},
{"error",
{
"error",
nil,
true,
},
{"a record",
&IPRecord{1, []net.Address{net.ParseAddress("8.8.8.8"), net.ParseAddress("8.8.4.4")},
time.Time{}, dnsmessage.RCodeSuccess},
{
"a record",
&IPRecord{
1,
[]net.Address{net.ParseAddress("8.8.8.8"), net.ParseAddress("8.8.4.4")},
time.Time{},
dnsmessage.RCodeSuccess,
},
false,
},
{"aaaa record",
{
"aaaa record",
&IPRecord{2, []net.Address{net.ParseAddress("2001::123:8888"), net.ParseAddress("2001::123:8844")}, time.Time{}, dnsmessage.RCodeSuccess},
false,
},
Expand Down
4 changes: 2 additions & 2 deletions app/dns/fakedns/fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ func (fkdns *Holder) GetFakeIPForDomain(domain string) []net.Address {
if v, ok := fkdns.domainToIP.Get(domain); ok {
return []net.Address{v.(net.Address)}
}
var currentTimeMillis = uint64(time.Now().UnixNano() / 1e6)
currentTimeMillis := uint64(time.Now().UnixNano() / 1e6)
ones, bits := fkdns.ipRange.Mask.Size()
rooms := bits - ones
if rooms < 64 {
currentTimeMillis %= (uint64(1) << rooms)
}
var bigIntIP = big.NewInt(0).SetBytes(fkdns.ipRange.IP)
bigIntIP := big.NewInt(0).SetBytes(fkdns.ipRange.IP)
bigIntIP = bigIntIP.Add(bigIntIP, new(big.Int).SetUint64(currentTimeMillis))
var ip net.Address
for {
Expand Down
4 changes: 1 addition & 3 deletions app/dns/fakedns/fakedns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ import (
"github.com/xtls/xray-core/features/dns"
)

var (
ipPrefix = "198.18."
)
var ipPrefix = "198.18."

func TestNewFakeDnsHolder(_ *testing.T) {
_, err := NewFakeDNSHolder()
Expand Down
3 changes: 2 additions & 1 deletion app/dns/nameserver_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package dns

import (
"context"
"github.com/xtls/xray-core/features/dns"
"strings"

"github.com/xtls/xray-core/features/dns"

"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/features/dns/localdns"
)
Expand Down
3 changes: 2 additions & 1 deletion app/dns/nameserver_local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package dns_test

import (
"context"
"github.com/xtls/xray-core/common/net"
"testing"
"time"

"github.com/xtls/xray-core/common/net"

. "github.com/xtls/xray-core/app/dns"
"github.com/xtls/xray-core/common"
"github.com/xtls/xray-core/features/dns"
Expand Down
3 changes: 2 additions & 1 deletion app/dns/nameserver_quic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package dns_test

import (
"context"
"github.com/xtls/xray-core/features/dns"
"net/url"
"testing"
"time"

"github.com/xtls/xray-core/features/dns"

"github.com/google/go-cmp/cmp"

. "github.com/xtls/xray-core/app/dns"
Expand Down
4 changes: 1 addition & 3 deletions app/log/log_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ type HandlerCreatorOptions struct {

type HandlerCreator func(LogType, HandlerCreatorOptions) (log.Handler, error)

var (
handlerCreatorMap = make(map[LogType]HandlerCreator)
)
var handlerCreatorMap = make(map[LogType]HandlerCreator)

func RegisterHandlerCreator(logType LogType, f HandlerCreator) error {
if f == nil {
Expand Down
1 change: 1 addition & 0 deletions app/proxyman/inbound/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,7 @@ func (w *dsWorker) Proxy() proxy.Inbound {
func (w *dsWorker) Port() net.Port {
return net.Port(0)
}

func (w *dsWorker) Start() error {
ctx := context.Background()
hub, err := internet.ListenUnix(ctx, w.address, w.stream, func(conn stat.Connection) {
Expand Down
3 changes: 1 addition & 2 deletions app/router/balancing.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ type BalancingStrategy interface {
PickOutbound([]string) string
}

type RandomStrategy struct {
}
type RandomStrategy struct{}

func (s *RandomStrategy) PickOutbound(tags []string) string {
n := len(tags)
Expand Down
4 changes: 1 addition & 3 deletions app/router/condition_geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,4 @@ func (c *GeoIPMatcherContainer) Add(geoip *GeoIP) (*GeoIPMatcher, error) {
return m, nil
}

var (
globalGeoIPContainer GeoIPMatcherContainer
)
var globalGeoIPContainer GeoIPMatcherContainer
3 changes: 2 additions & 1 deletion app/router/condition_geoip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func TestGeoIPMatcher(t *testing.T) {
{
Input: "192.0.1.0",
Output: false,
}, {
},
{
Input: "0.1.0.0",
Output: true,
},
Expand Down
1 change: 0 additions & 1 deletion app/router/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ func (rr *RoutingRule) BuildCondition() (Condition, error) {
newError("MphDomainMatcher is enabled for ", len(rr.Domain), " domain rule(s)").AtDebug().WriteToLog()
conds.Add(matcher)
}

}

if len(rr.UserEmail) > 0 {
Expand Down
1 change: 0 additions & 1 deletion app/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ func (r *Router) PickRoute(ctx routing.Context) (routing.Route, error) {
}

func (r *Router) pickRouteInternal(ctx routing.Context) (*Rule, routing.Context, error) {

// SkipDNSResolve is set from DNS module.
// the DOH remote server maybe a domain name,
// this prevents cycle resolving dead loop
Expand Down
3 changes: 2 additions & 1 deletion app/router/router_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package router_test

import (
"context"
"github.com/xtls/xray-core/features/dns"
"testing"

"github.com/xtls/xray-core/features/dns"

"github.com/golang/mock/gomock"

. "github.com/xtls/xray-core/app/router"
Expand Down
1 change: 1 addition & 0 deletions common/buf/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestBufferByte(t *testing.T) {
buffer.Release()
}
}

func TestBufferResize(t *testing.T) {
buffer := New()
defer buffer.Release()
Expand Down
2 changes: 1 addition & 1 deletion common/buf/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func NewWriter(writer io.Writer) Writer {
return mw
}

var iConn = writer
iConn := writer
if statConn, ok := writer.(*stat.CounterConnection); ok {
iConn = statConn.Connection
}
Expand Down
6 changes: 2 additions & 4 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ import (

//go:generate go run github.com/xtls/xray-core/common/errors/errorgen

var (
// ErrNoClue is for the situation that existing information is not enough to make a decision. For example, Router may return this error when there is no suitable route.
ErrNoClue = errors.New("not enough information for making a decision")
)
// ErrNoClue is for the situation that existing information is not enough to make a decision. For example, Router may return this error when there is no suitable route.
var ErrNoClue = errors.New("not enough information for making a decision")

// Must panics if err is not nil.
func Must(err error) {
Expand Down
1 change: 0 additions & 1 deletion common/crypto/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ func (w *AuthenticationWriter) writeStream(mb buf.MultiBuffer) error {
mb = nb

eb, err := w.seal(rawBytes[:nBytes])

if err != nil {
buf.ReleaseMulti(mb2Write)
return err
Expand Down
2 changes: 1 addition & 1 deletion common/crypto/chacha20_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func mustDecodeHex(s string) []byte {
}

func TestChaCha20Stream(t *testing.T) {
var cases = []struct {
cases := []struct {
key []byte
iv []byte
output []byte
Expand Down
2 changes: 1 addition & 1 deletion common/crypto/internal/chacha_core.generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package internal
import "encoding/binary"

func ChaCha20Block(s *[16]uint32, out []byte, rounds int) {
var x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 = s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15]
x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, x12, x13, x14, x15 := s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11], s[12], s[13], s[14], s[15]
for i := 0; i < rounds; i += 2 {
var x uint32

Expand Down
2 changes: 1 addition & 1 deletion common/crypto/internal/chacha_core_gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func ChaCha20Block(s *[16]uint32, out []byte, rounds int) {
}

func main() {
file, err := os.OpenFile("chacha_core.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
file, err := os.OpenFile("chacha_core.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0o644)
if err != nil {
log.Fatalf("Failed to generate chacha_core.go: %v", err)
}
Expand Down
4 changes: 1 addition & 3 deletions common/crypto/io.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ func (r *CryptionReader) Read(data []byte) (int, error) {
return nBytes, err
}

var (
_ buf.Writer = (*CryptionWriter)(nil)
)
var _ buf.Writer = (*CryptionWriter)(nil)

type CryptionWriter struct {
stream cipher.Stream
Expand Down
2 changes: 1 addition & 1 deletion common/errors/errorgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func main() {
pkg = "core"
}

file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
file, err := os.OpenFile("errors.generated.go", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0o644)
if err != nil {
fmt.Printf("Failed to generate errors.generated.go: %v", err)
os.Exit(1)
Expand Down
4 changes: 1 addition & 3 deletions common/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func Record(msg Message) {
logHandler.Handle(msg)
}

var (
logHandler syncHandler
)
var logHandler syncHandler

// RegisterHandler register a new handler as current log handler. Previous registered handler will be discarded.
func RegisterHandler(handler Handler) {
Expand Down
4 changes: 2 additions & 2 deletions common/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,13 @@ func CreateStderrLogWriter() WriterCreator {

// CreateFileLogWriter returns a LogWriterCreator that creates LogWriter for the given file.
func CreateFileLogWriter(path string) (WriterCreator, error) {
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o600)
if err != nil {
return nil, err
}
file.Close()
return func() Writer {
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600)
file, err := os.OpenFile(path, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0o600)
if err != nil {
return nil
}
Expand Down
7 changes: 4 additions & 3 deletions common/mux/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ func (f *DialingWorkerFactory) Create() (*ClientWorker, error) {
Reader: downlinkReader,
Writer: upLinkWriter,
}, f.Strategy)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -175,8 +174,10 @@ type ClientWorker struct {
strategy ClientStrategy
}

var muxCoolAddress = net.DomainAddress("v1.mux.cool")
var muxCoolPort = net.Port(9527)
var (
muxCoolAddress = net.DomainAddress("v1.mux.cool")
muxCoolPort = net.Port(9527)
)

// NewClientWorker creates a new mux.Client.
func NewClientWorker(stream transport.Link, s ClientStrategy) (*ClientWorker, error) {
Expand Down
Loading

0 comments on commit e286cdc

Please sign in to comment.