Browse Source

Fix according to go vet results

loyalsoldier 5 years ago
parent
commit
f9175e3bc8

+ 2 - 2
app/policy/config.go

@@ -50,8 +50,8 @@ func (p *Policy) overrideWith(another *Policy) {
 		p.Timeout.overrideWith(another.Timeout)
 	}
 	if another.Stats != nil && p.Stats == nil {
-		p.Stats = new(Policy_Stats)
-		*p.Stats = *another.Stats
+		p.Stats = &Policy_Stats{}
+		p.Stats = another.Stats
 	}
 	if another.Buffer != nil {
 		p.Buffer = &Policy_Buffer{

+ 3 - 3
common/net/port.go

@@ -44,17 +44,17 @@ func (p Port) String() string {
 }
 
 // FromPort returns the beginning port of this PortRange.
-func (p PortRange) FromPort() Port {
+func (p *PortRange) FromPort() Port {
 	return Port(p.From)
 }
 
 // ToPort returns the end port of this PortRange.
-func (p PortRange) ToPort() Port {
+func (p *PortRange) ToPort() Port {
 	return Port(p.To)
 }
 
 // Contains returns true if the given port is within the range of a PortRange.
-func (p PortRange) Contains(port Port) bool {
+func (p *PortRange) Contains(port Port) bool {
 	return p.FromPort() <= port && port <= p.ToPort()
 }
 

+ 1 - 1
common/protocol/server_spec.go

@@ -58,7 +58,7 @@ func NewServerSpec(dest net.Destination, valid ValidationStrategy, users ...*Mem
 	}
 }
 
-func NewServerSpecFromPB(spec ServerEndpoint) (*ServerSpec, error) {
+func NewServerSpecFromPB(spec *ServerEndpoint) (*ServerSpec, error) {
 	dest := net.TCPDestination(spec.Address.AsAddress(), net.Port(spec.Port))
 	mUsers := make([]*MemoryUser, len(spec.User))
 	for idx, u := range spec.User {

+ 5 - 5
proxy/dns/dns_test.go

@@ -135,7 +135,7 @@ func TestUDPDNSTunnel(t *testing.T) {
 		m1.Id = dns.Id()
 		m1.RecursionDesired = true
 		m1.Question = make([]dns.Question, 1)
-		m1.Question[0] = dns.Question{"google.com.", dns.TypeA, dns.ClassINET}
+		m1.Question[0] = dns.Question{Name: "google.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET}
 
 		c := new(dns.Client)
 		in, _, err := c.Exchange(m1, "127.0.0.1:"+strconv.Itoa(int(serverPort)))
@@ -159,7 +159,7 @@ func TestUDPDNSTunnel(t *testing.T) {
 		m1.Id = dns.Id()
 		m1.RecursionDesired = true
 		m1.Question = make([]dns.Question, 1)
-		m1.Question[0] = dns.Question{"ipv4only.google.com.", dns.TypeAAAA, dns.ClassINET}
+		m1.Question[0] = dns.Question{Name: "ipv4only.google.com.", Qtype: dns.TypeAAAA, Qclass: dns.ClassINET}
 
 		c := new(dns.Client)
 		c.Timeout = 10 * time.Second
@@ -176,7 +176,7 @@ func TestUDPDNSTunnel(t *testing.T) {
 		m1.Id = dns.Id()
 		m1.RecursionDesired = true
 		m1.Question = make([]dns.Question, 1)
-		m1.Question[0] = dns.Question{"notexist.google.com.", dns.TypeAAAA, dns.ClassINET}
+		m1.Question[0] = dns.Question{Name: "notexist.google.com.", Qtype: dns.TypeAAAA, Qclass: dns.ClassINET}
 
 		c := new(dns.Client)
 		in, _, err := c.Exchange(m1, "127.0.0.1:"+strconv.Itoa(int(serverPort)))
@@ -253,7 +253,7 @@ func TestTCPDNSTunnel(t *testing.T) {
 	m1.Id = dns.Id()
 	m1.RecursionDesired = true
 	m1.Question = make([]dns.Question, 1)
-	m1.Question[0] = dns.Question{"google.com.", dns.TypeA, dns.ClassINET}
+	m1.Question[0] = dns.Question{Name: "google.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET}
 
 	c := &dns.Client{
 		Net: "tcp",
@@ -343,7 +343,7 @@ func TestUDP2TCPDNSTunnel(t *testing.T) {
 	m1.Id = dns.Id()
 	m1.RecursionDesired = true
 	m1.Question = make([]dns.Question, 1)
-	m1.Question[0] = dns.Question{"google.com.", dns.TypeA, dns.ClassINET}
+	m1.Question[0] = dns.Question{Name: "google.com.", Qtype: dns.TypeA, Qclass: dns.ClassINET}
 
 	c := &dns.Client{
 		Net: "tcp",

+ 2 - 2
proxy/freedom/freedom.go

@@ -39,12 +39,12 @@ func init() {
 type Handler struct {
 	policyManager policy.Manager
 	dns           dns.Client
-	config        Config
+	config        *Config
 }
 
 // Init initializes the Handler with necessary parameters.
 func (h *Handler) Init(config *Config, pm policy.Manager, d dns.Client) error {
-	h.config = *config
+	h.config = config
 	h.policyManager = pm
 	h.dns = d
 

+ 1 - 1
proxy/http/client.go

@@ -48,7 +48,7 @@ var (
 func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
 	serverList := protocol.NewServerList()
 	for _, rec := range config.Server {
-		s, err := protocol.NewServerSpecFromPB(*rec)
+		s, err := protocol.NewServerSpecFromPB(rec)
 		if err != nil {
 			return nil, newError("failed to get server spec").Base(err)
 		}

+ 1 - 1
proxy/shadowsocks/client.go

@@ -29,7 +29,7 @@ type Client struct {
 func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
 	serverList := protocol.NewServerList()
 	for _, rec := range config.Server {
-		s, err := protocol.NewServerSpecFromPB(*rec)
+		s, err := protocol.NewServerSpecFromPB(rec)
 		if err != nil {
 			return nil, newError("failed to parse server spec").Base(err)
 		}

+ 2 - 2
proxy/shadowsocks/server.go

@@ -23,7 +23,7 @@ import (
 )
 
 type Server struct {
-	config        ServerConfig
+	config        *ServerConfig
 	user          *protocol.MemoryUser
 	policyManager policy.Manager
 }
@@ -41,7 +41,7 @@ func NewServer(ctx context.Context, config *ServerConfig) (*Server, error) {
 
 	v := core.MustFromContext(ctx)
 	s := &Server{
-		config:        *config,
+		config:        config,
 		user:          mUser,
 		policyManager: v.GetFeature(policy.ManagerType()).(policy.Manager),
 	}

+ 1 - 1
proxy/socks/client.go

@@ -30,7 +30,7 @@ type Client struct {
 func NewClient(ctx context.Context, config *ClientConfig) (*Client, error) {
 	serverList := protocol.NewServerList()
 	for _, rec := range config.Server {
-		s, err := protocol.NewServerSpecFromPB(*rec)
+		s, err := protocol.NewServerSpecFromPB(rec)
 		if err != nil {
 			return nil, newError("failed to get server spec").Base(err)
 		}

+ 1 - 1
proxy/vless/outbound/outbound.go

@@ -42,7 +42,7 @@ func New(ctx context.Context, config *Config) (*Handler, error) {
 
 	serverList := protocol.NewServerList()
 	for _, rec := range config.Receiver {
-		s, err := protocol.NewServerSpecFromPB(*rec)
+		s, err := protocol.NewServerSpecFromPB(rec)
 		if err != nil {
 			return nil, newError("failed to parse server spec").Base(err).AtError()
 		}

+ 1 - 1
proxy/vmess/outbound/outbound.go

@@ -36,7 +36,7 @@ type Handler struct {
 func New(ctx context.Context, config *Config) (*Handler, error) {
 	serverList := protocol.NewServerList()
 	for _, rec := range config.Receiver {
-		s, err := protocol.NewServerSpecFromPB(*rec)
+		s, err := protocol.NewServerSpecFromPB(rec)
 		if err != nil {
 			return nil, newError("failed to parse server spec").Base(err)
 		}

+ 2 - 2
transport/internet/http/hub.go

@@ -25,7 +25,7 @@ type Listener struct {
 	server  *http.Server
 	handler internet.ConnHandler
 	local   net.Addr
-	config  Config
+	config  *Config
 }
 
 func (l *Listener) Addr() net.Addr {
@@ -102,7 +102,7 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
 			IP:   address.IP(),
 			Port: int(port),
 		},
-		config: *httpSettings,
+		config: httpSettings,
 	}
 
 	var server *http.Server