1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-13 11:20:42 +00:00

Fix according to go vet results

This commit is contained in:
loyalsoldier 2020-08-26 19:35:33 +08:00
parent 30edcef67a
commit f9175e3bc8
No known key found for this signature in database
GPG Key ID: 23829BBC1ACF2C90
12 changed files with 22 additions and 22 deletions

View File

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

View File

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

View File

@ -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)) dest := net.TCPDestination(spec.Address.AsAddress(), net.Port(spec.Port))
mUsers := make([]*MemoryUser, len(spec.User)) mUsers := make([]*MemoryUser, len(spec.User))
for idx, u := range spec.User { for idx, u := range spec.User {

View File

@ -135,7 +135,7 @@ func TestUDPDNSTunnel(t *testing.T) {
m1.Id = dns.Id() m1.Id = dns.Id()
m1.RecursionDesired = true m1.RecursionDesired = true
m1.Question = make([]dns.Question, 1) 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) c := new(dns.Client)
in, _, err := c.Exchange(m1, "127.0.0.1:"+strconv.Itoa(int(serverPort))) 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.Id = dns.Id()
m1.RecursionDesired = true m1.RecursionDesired = true
m1.Question = make([]dns.Question, 1) 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 := new(dns.Client)
c.Timeout = 10 * time.Second c.Timeout = 10 * time.Second
@ -176,7 +176,7 @@ func TestUDPDNSTunnel(t *testing.T) {
m1.Id = dns.Id() m1.Id = dns.Id()
m1.RecursionDesired = true m1.RecursionDesired = true
m1.Question = make([]dns.Question, 1) 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) c := new(dns.Client)
in, _, err := c.Exchange(m1, "127.0.0.1:"+strconv.Itoa(int(serverPort))) 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.Id = dns.Id()
m1.RecursionDesired = true m1.RecursionDesired = true
m1.Question = make([]dns.Question, 1) 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{ c := &dns.Client{
Net: "tcp", Net: "tcp",
@ -343,7 +343,7 @@ func TestUDP2TCPDNSTunnel(t *testing.T) {
m1.Id = dns.Id() m1.Id = dns.Id()
m1.RecursionDesired = true m1.RecursionDesired = true
m1.Question = make([]dns.Question, 1) 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{ c := &dns.Client{
Net: "tcp", Net: "tcp",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ type Listener struct {
server *http.Server server *http.Server
handler internet.ConnHandler handler internet.ConnHandler
local net.Addr local net.Addr
config Config config *Config
} }
func (l *Listener) Addr() net.Addr { 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(), IP: address.IP(),
Port: int(port), Port: int(port),
}, },
config: *httpSettings, config: httpSettings,
} }
var server *http.Server var server *http.Server