Upgrade to go 1.14

This commit is contained in:
Cyrille Nofficial 2020-04-04 12:32:27 +02:00
parent 021d4519ee
commit 329f429f83
12 changed files with 28 additions and 126 deletions

View File

@ -19,7 +19,7 @@ WORKDIR /src
ADD . . ADD . .
RUN CGO_LDFLAGS="$(pkg-config --libs opencv4)" \ RUN CGO_LDFLAGS="$(pkg-config --libs opencv4)" \
CGO_ENABLED=1 CGO_CPPFLAGS=${CGO_CPPFLAGS} CGO_CXXFLAGS=${CGO_CXXFLAGS} CGO_LDFLAGS=${CGO_LDFLAGS} GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -mod vendor -a ./cmd/rc-camera/ CGO_ENABLED=1 CGO_CPPFLAGS=${CGO_CPPFLAGS} CGO_CXXFLAGS=${CGO_CXXFLAGS} CGO_LDFLAGS=${CGO_LDFLAGS} GOOS=${GOOS} GOARCH=${GOARCH} GOARM=${GOARM} go build -a ./cmd/rc-camera/

View File

@ -1,10 +1,11 @@
.PHONY: test docker .PHONY: test docker
DOCKER_IMG = cyrilix/robocar-camera DOCKER_IMG = cyrilix/robocar-camera
TAG = latest
test: test:
go test -mod vendor ./cmd/rc-camera ./camera go test ./...
docker: docker:
docker buildx build . --platform linux/arm/7,linux/arm64,linux/amd64 -t ${DOCKER_IMG} --push docker buildx build . --platform linux/arm/7,linux/arm64,linux/amd64 -t ${DOCKER_IMG}:${TAG} --push

3
go.mod
View File

@ -1,6 +1,6 @@
module github.com/cyrilix/robocar-camera module github.com/cyrilix/robocar-camera
go 1.13 go 1.14
require ( require (
github.com/cyrilix/robocar-base v0.1.0 github.com/cyrilix/robocar-base v0.1.0
@ -9,5 +9,4 @@ require (
github.com/golang/protobuf v1.3.4 github.com/golang/protobuf v1.3.4
github.com/sirupsen/logrus v1.4.2 github.com/sirupsen/logrus v1.4.2
gocv.io/x/gocv v0.21.0 gocv.io/x/gocv v0.21.0
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
) )

BIN
rc-camera Executable file

Binary file not shown.

View File

@ -127,7 +127,7 @@ type Dialer struct {
// establishing the transport connection. // establishing the transport connection.
ProxyDial func(context.Context, string, string) (net.Conn, error) ProxyDial func(context.Context, string, string) (net.Conn, error)
// AuthMethods specifies the list of request authentication // AuthMethods specifies the list of request authention
// methods. // methods.
// If empty, SOCKS client requests only AuthMethodNotRequired. // If empty, SOCKS client requests only AuthMethodNotRequired.
AuthMethods []AuthMethod AuthMethods []AuthMethod
@ -224,7 +224,6 @@ func (d *Dialer) Dial(network, address string) (net.Conn, error) {
return nil, &net.OpError{Op: d.cmd.String(), Net: network, Source: proxy, Addr: dst, Err: err} return nil, &net.OpError{Op: d.cmd.String(), Net: network, Source: proxy, Addr: dst, Err: err}
} }
if _, err := d.DialWithConn(context.Background(), c, network, address); err != nil { if _, err := d.DialWithConn(context.Background(), c, network, address); err != nil {
c.Close()
return nil, err return nil, err
} }
return c, nil return c, nil

View File

@ -1,54 +0,0 @@
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package proxy
import (
"context"
"net"
)
// A ContextDialer dials using a context.
type ContextDialer interface {
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}
// Dial works like DialContext on net.Dialer but using a dialer returned by FromEnvironment.
//
// The passed ctx is only used for returning the Conn, not the lifetime of the Conn.
//
// Custom dialers (registered via RegisterDialerType) that do not implement ContextDialer
// can leak a goroutine for as long as it takes the underlying Dialer implementation to timeout.
//
// A Conn returned from a successful Dial after the context has been cancelled will be immediately closed.
func Dial(ctx context.Context, network, address string) (net.Conn, error) {
d := FromEnvironment()
if xd, ok := d.(ContextDialer); ok {
return xd.DialContext(ctx, network, address)
}
return dialContext(ctx, d, network, address)
}
// WARNING: this can leak a goroutine for as long as the underlying Dialer implementation takes to timeout
// A Conn returned from a successful Dial after the context has been cancelled will be immediately closed.
func dialContext(ctx context.Context, d Dialer, network, address string) (net.Conn, error) {
var (
conn net.Conn
done = make(chan struct{}, 1)
err error
)
go func() {
conn, err = d.Dial(network, address)
close(done)
if conn != nil && ctx.Err() != nil {
conn.Close()
}
}()
select {
case <-ctx.Done():
err = ctx.Err()
case <-done:
}
return conn, err
}

View File

@ -5,27 +5,14 @@
package proxy package proxy
import ( import (
"context"
"net" "net"
) )
type direct struct{} type direct struct{}
// Direct implements Dialer by making network connections directly using net.Dial or net.DialContext. // Direct is a direct proxy: one that makes network connections directly.
var Direct = direct{} var Direct = direct{}
var (
_ Dialer = Direct
_ ContextDialer = Direct
)
// Dial directly invokes net.Dial with the supplied parameters.
func (direct) Dial(network, addr string) (net.Conn, error) { func (direct) Dial(network, addr string) (net.Conn, error) {
return net.Dial(network, addr) return net.Dial(network, addr)
} }
// DialContext instantiates a net.Dialer and invokes its DialContext receiver with the supplied parameters.
func (direct) DialContext(ctx context.Context, network, addr string) (net.Conn, error) {
var d net.Dialer
return d.DialContext(ctx, network, addr)
}

View File

@ -5,7 +5,6 @@
package proxy package proxy
import ( import (
"context"
"net" "net"
"strings" "strings"
) )
@ -42,20 +41,6 @@ func (p *PerHost) Dial(network, addr string) (c net.Conn, err error) {
return p.dialerForRequest(host).Dial(network, addr) return p.dialerForRequest(host).Dial(network, addr)
} }
// DialContext connects to the address addr on the given network through either
// defaultDialer or bypass.
func (p *PerHost) DialContext(ctx context.Context, network, addr string) (c net.Conn, err error) {
host, _, err := net.SplitHostPort(addr)
if err != nil {
return nil, err
}
d := p.dialerForRequest(host)
if x, ok := d.(ContextDialer); ok {
return x.DialContext(ctx, network, addr)
}
return dialContext(ctx, d, network, addr)
}
func (p *PerHost) dialerForRequest(host string) Dialer { func (p *PerHost) dialerForRequest(host string) Dialer {
if ip := net.ParseIP(host); ip != nil { if ip := net.ParseIP(host); ip != nil {
for _, net := range p.bypassNetworks { for _, net := range p.bypassNetworks {

View File

@ -15,7 +15,6 @@ import (
) )
// A Dialer is a means to establish a connection. // A Dialer is a means to establish a connection.
// Custom dialers should also implement ContextDialer.
type Dialer interface { type Dialer interface {
// Dial connects to the given address via the proxy. // Dial connects to the given address via the proxy.
Dial(network, addr string) (c net.Conn, err error) Dial(network, addr string) (c net.Conn, err error)
@ -26,30 +25,21 @@ type Auth struct {
User, Password string User, Password string
} }
// FromEnvironment returns the dialer specified by the proxy-related // FromEnvironment returns the dialer specified by the proxy related variables in
// variables in the environment and makes underlying connections // the environment.
// directly.
func FromEnvironment() Dialer { func FromEnvironment() Dialer {
return FromEnvironmentUsing(Direct)
}
// FromEnvironmentUsing returns the dialer specify by the proxy-related
// variables in the environment and makes underlying connections
// using the provided forwarding Dialer (for instance, a *net.Dialer
// with desired configuration).
func FromEnvironmentUsing(forward Dialer) Dialer {
allProxy := allProxyEnv.Get() allProxy := allProxyEnv.Get()
if len(allProxy) == 0 { if len(allProxy) == 0 {
return forward return Direct
} }
proxyURL, err := url.Parse(allProxy) proxyURL, err := url.Parse(allProxy)
if err != nil { if err != nil {
return forward return Direct
} }
proxy, err := FromURL(proxyURL, forward) proxy, err := FromURL(proxyURL, Direct)
if err != nil { if err != nil {
return forward return Direct
} }
noProxy := noProxyEnv.Get() noProxy := noProxyEnv.Get()
@ -57,7 +47,7 @@ func FromEnvironmentUsing(forward Dialer) Dialer {
return proxy return proxy
} }
perHost := NewPerHost(proxy, forward) perHost := NewPerHost(proxy, Direct)
perHost.AddFromString(noProxy) perHost.AddFromString(noProxy)
return perHost return perHost
} }
@ -89,13 +79,8 @@ func FromURL(u *url.URL, forward Dialer) (Dialer, error) {
} }
switch u.Scheme { switch u.Scheme {
case "socks5", "socks5h": case "socks5":
addr := u.Hostname() return SOCKS5("tcp", u.Host, auth, forward)
port := u.Port()
if port == "" {
port = "1080"
}
return SOCKS5("tcp", net.JoinHostPort(addr, port), auth, forward)
} }
// If the scheme doesn't match any of the built-in schemes, see if it // If the scheme doesn't match any of the built-in schemes, see if it

View File

@ -17,14 +17,8 @@ import (
func SOCKS5(network, address string, auth *Auth, forward Dialer) (Dialer, error) { func SOCKS5(network, address string, auth *Auth, forward Dialer) (Dialer, error) {
d := socks.NewDialer(network, address) d := socks.NewDialer(network, address)
if forward != nil { if forward != nil {
if f, ok := forward.(ContextDialer); ok { d.ProxyDial = func(_ context.Context, network string, address string) (net.Conn, error) {
d.ProxyDial = func(ctx context.Context, network string, address string) (net.Conn, error) { return forward.Dial(network, address)
return f.DialContext(ctx, network, address)
}
} else {
d.ProxyDial = func(ctx context.Context, network string, address string) (net.Conn, error) {
return dialContext(ctx, forward, network, address)
}
} }
} }
if auth != nil { if auth != nil {

View File

@ -5,11 +5,11 @@
// Package websocket implements a client and server for the WebSocket protocol // Package websocket implements a client and server for the WebSocket protocol
// as specified in RFC 6455. // as specified in RFC 6455.
// //
// This package currently lacks some features found in alternative // This package currently lacks some features found in an alternative
// and more actively maintained WebSocket packages: // and more actively maintained WebSocket package:
// //
// https://godoc.org/github.com/gorilla/websocket // https://godoc.org/github.com/gorilla/websocket
// https://godoc.org/nhooyr.io/websocket //
package websocket // import "golang.org/x/net/websocket" package websocket // import "golang.org/x/net/websocket"
import ( import (

8
vendor/modules.txt vendored
View File

@ -1,21 +1,27 @@
# github.com/cyrilix/robocar-base v0.1.0 # github.com/cyrilix/robocar-base v0.1.0
## explicit
github.com/cyrilix/robocar-base/cli github.com/cyrilix/robocar-base/cli
github.com/cyrilix/robocar-base/service github.com/cyrilix/robocar-base/service
# github.com/cyrilix/robocar-protobuf/go v1.0.0 # github.com/cyrilix/robocar-protobuf/go v1.0.0
## explicit
github.com/cyrilix/robocar-protobuf/go/events github.com/cyrilix/robocar-protobuf/go/events
# github.com/eclipse/paho.mqtt.golang v1.2.0 # github.com/eclipse/paho.mqtt.golang v1.2.0
## explicit
github.com/eclipse/paho.mqtt.golang github.com/eclipse/paho.mqtt.golang
github.com/eclipse/paho.mqtt.golang/packets github.com/eclipse/paho.mqtt.golang/packets
# github.com/golang/protobuf v1.3.4 # github.com/golang/protobuf v1.3.4
## explicit
github.com/golang/protobuf/proto github.com/golang/protobuf/proto
github.com/golang/protobuf/ptypes/timestamp github.com/golang/protobuf/ptypes/timestamp
# github.com/konsorten/go-windows-terminal-sequences v1.0.1 # github.com/konsorten/go-windows-terminal-sequences v1.0.1
github.com/konsorten/go-windows-terminal-sequences github.com/konsorten/go-windows-terminal-sequences
# github.com/sirupsen/logrus v1.4.2 # github.com/sirupsen/logrus v1.4.2
## explicit
github.com/sirupsen/logrus github.com/sirupsen/logrus
# gocv.io/x/gocv v0.21.0 # gocv.io/x/gocv v0.21.0
## explicit
gocv.io/x/gocv gocv.io/x/gocv
# golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 # golang.org/x/net v0.0.0-20180906233101-161cd47e91fd
golang.org/x/net/internal/socks golang.org/x/net/internal/socks
golang.org/x/net/proxy golang.org/x/net/proxy
golang.org/x/net/websocket golang.org/x/net/websocket