Skip to content

Commit

Permalink
fixes nanomsg#155 Numerous golint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
gdamore committed Nov 9, 2015
1 parent 9010b99 commit cbca8e7
Show file tree
Hide file tree
Showing 33 changed files with 188 additions and 153 deletions.
2 changes: 2 additions & 0 deletions compat/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import (
// either normal or raw mode sockets.
type Domain int

// Constants for socket type.
const (
AF_SP = Domain(0)
AF_SP_RAW = Domain(1)
Expand All @@ -65,6 +66,7 @@ const (
// that Mangos supports.
type Protocol int

// Constants for protocols.
const (
PUSH = Protocol(mangos.ProtoPush)
PULL = Protocol(mangos.ProtoPull)
Expand Down
2 changes: 1 addition & 1 deletion core.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func newSocket(proto Protocol) *socket {

// MakeSocket is intended for use by Protocol implementations. The intention
// is that they can wrap this to provide a "proto.NewSocket()" implementation.
func MakeSocket(proto Protocol) *socket {
func MakeSocket(proto Protocol) Socket {
return newSocket(proto)
}

Expand Down
5 changes: 3 additions & 2 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"errors"
)

// Various error codes.
var (
ErrBadAddr = errors.New("invalid address")
ErrBadHeader = errors.New("invalid header received")
Expand All @@ -39,6 +40,6 @@ var (
ErrGarbled = errors.New("message garbled")
ErrAddrInUse = errors.New("address in use")
ErrBadProperty = errors.New("invalid property name")
ErrTlsNoConfig = errors.New("missing TLS configuration")
ErrTlsNoCert = errors.New("missing TLS certificates")
ErrTLSNoConfig = errors.New("missing TLS configuration")
ErrTLSNoCert = errors.New("missing TLS certificates")
)
14 changes: 7 additions & 7 deletions examples/pair/pair.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,27 @@ func die(format string, v ...interface{}) {
os.Exit(1)
}

func send_name(sock mangos.Socket, name string) {
func sendName(sock mangos.Socket, name string) {
fmt.Printf("%s: SENDING \"%s\"\n", name, name)
if err := sock.Send([]byte(name)); err != nil {
die("failed sending: %s", err)
}
}

func recv_name(sock mangos.Socket, name string) {
func recvName(sock mangos.Socket, name string) {
var msg []byte
var err error
if msg, err = sock.Recv(); err == nil {
fmt.Printf("%s: RECEIVED: \"%s\"\n", name, string(msg))
}
}

func send_recv(sock mangos.Socket, name string) {
func sendRecv(sock mangos.Socket, name string) {
for {
sock.SetOption(mangos.OptionRecvDeadline, 100*time.Millisecond)
recv_name(sock, name)
recvName(sock, name)
time.Sleep(time.Second)
send_name(sock, name)
sendName(sock, name)
}
}

Expand All @@ -77,7 +77,7 @@ func node0(url string) {
if err = sock.Listen(url); err != nil {
die("can't listen on pair socket: %s", err.Error())
}
send_recv(sock, "node0")
sendRecv(sock, "node0")
}

func node1(url string) {
Expand All @@ -92,7 +92,7 @@ func node1(url string) {
if err = sock.Dial(url); err != nil {
die("can't dial on pair socket: %s", err.Error())
}
send_recv(sock, "node1")
sendRecv(sock, "node1")
}

func main() {
Expand Down
8 changes: 4 additions & 4 deletions macat/macat.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ var proto string
var dialAddrs []string
var listenAddrs []string
var subscriptions []string
var recvTimeout int = -1
var sendTimeout int = -1
var sendInterval int = -1
var recvTimeout = -1
var sendTimeout = -1
var sendInterval = -1
var sendDelay int
var sendData []byte
var printFormat string
Expand Down Expand Up @@ -553,7 +553,7 @@ func main() {
fatalf("Protocol not specified.")
}

sock.SetOption(mangos.OptionTlsConfig, &tlscfg)
sock.SetOption(mangos.OptionTLSConfig, &tlscfg)

if len(listenAddrs) == 0 && len(dialAddrs) == 0 {
fatalf("No address specified.")
Expand Down
6 changes: 3 additions & 3 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ const (
// indicate an infinite time. Default is 1 second.
OptionSurveyTime = "SURVEY-TIME"

// OptionTlsConfig is used to supply TLS configuration details.
// OptionTLSConfig is used to supply TLS configuration details.
// The parameter is a tls.Config pointer.
OptionTlsConfig = "TLS-CONFIG"
OptionTLSConfig = "TLS-CONFIG"

// OptionWriteQLen is used to set the size, in messages, of the write
// queue channel. By default, it's 128. This option cannot be set if
Expand Down Expand Up @@ -109,7 +109,7 @@ const (
// those that do, if a message traverses more than this many devices,
// it will be dropped. This is used to provide protection against
// loops in the topology. The default is protocol specific.
OptionTtl = "TTL"
OptionTTL = "TTL"

// OptionMaxRecvSize supplies the maximum receive size for inbound
// messages. This option exists because the wire protocol allows
Expand Down
4 changes: 2 additions & 2 deletions perf/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"strconv"
)

func Usage() {
func usage() {
fmt.Printf("Bad Usage!\n")
os.Exit(1)
}
Expand Down Expand Up @@ -170,5 +170,5 @@ func main() {
args = args[1:]
}
}
Usage()
usage()
}
2 changes: 1 addition & 1 deletion perf/throughput.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
"time"
)

// LatencyServer is the server side -- very much equivalent to local_thr in
// ThroughputServer is the server side -- very much equivalent to local_thr in
// nanomsg/perf. It does the measurement by counting packets received.
func ThroughputServer(addr string, msgSize int, count int) {
s, err := pair.NewSocket()
Expand Down
1 change: 1 addition & 0 deletions port.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ type Port interface {
// PortAction determines whether the action on a Port is addition or removal.
type PortAction int

// PortAction values.
const (
PortActionAdd = iota
PortActionRemove
Expand Down
8 changes: 4 additions & 4 deletions properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ const (
// end dialer. The value is a net.Addr.
PropRemoteAddr = "REMOTE-ADDR"

// PropTlsConnState is used to supply TLS connection details. The
// PropTLSConnState is used to supply TLS connection details. The
// value is a tls.ConnectionState. It is only valid when TLS is used.
PropTlsConnState = "TLS-STATE"
PropTLSConnState = "TLS-STATE"

// PropHttpRequest conveys an *http.Request. This property only exists
// PropHTTPRequest conveys an *http.Request. This property only exists
// for websocket connections.
PropHttpRequest = "HTTP-REQUEST"
PropHTTPRequest = "HTTP-REQUEST"
)
9 changes: 6 additions & 3 deletions protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ const (
ProtoStar = (100 * 16)
)

// ProtocolName returns the name corresponding to a given protocol number.
// This is useful for transports like WebSocket, which use a text name
// rather than the number in the handshake.
func ProtocolName(number uint16) string {
names := map[uint16]string{
ProtoPair: "pair",
Expand Down Expand Up @@ -206,10 +209,10 @@ func ValidPeers(p1, p2 Protocol) bool {
// have no data to send.
func NullRecv(ep Endpoint) {
for {
if m := ep.RecvMsg(); m == nil {
var m *Message
if m = ep.RecvMsg(); m == nil {
return
} else {
m.Free()
}
m.Free()
}
}
2 changes: 1 addition & 1 deletion protocol/pull/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (x *pull) GetOption(name string) (interface{}, error) {
}
}

// NewProtocol() allocates a new PULL protocol object.
// NewProtocol allocates a new PULL protocol object.
func NewProtocol() mangos.Protocol {
return &pull{}
}
Expand Down
4 changes: 2 additions & 2 deletions protocol/rep/rep.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func (r *rep) SetOption(name string, v interface{}) error {
r.sock.SetSendError(mangos.ErrProtoState)
}
return nil
case mangos.OptionTtl:
case mangos.OptionTTL:
if ttl, ok := v.(int); !ok {
return mangos.ErrBadValue
} else if ttl < 1 || ttl > 255 {
Expand All @@ -282,7 +282,7 @@ func (r *rep) GetOption(name string) (interface{}, error) {
switch name {
case mangos.OptionRaw:
return r.raw, nil
case mangos.OptionTtl:
case mangos.OptionTTL:
return r.ttl, nil
default:
return nil, mangos.ErrBadOption
Expand Down
2 changes: 1 addition & 1 deletion protocol/req/req.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func (r *req) GetOption(option string) (interface{}, error) {
}
}

// NewReq returns a new REQ protocol object.
// NewProtocol returns a new REQ protocol object.
func NewProtocol() mangos.Protocol {
return &req{}
}
Expand Down
2 changes: 1 addition & 1 deletion protocol/respondent/respondent.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ func (x *resp) SetOption(name string, v interface{}) error {
x.sock.SetSendError(mangos.ErrProtoState)
}
return nil
case mangos.OptionTtl:
case mangos.OptionTTL:
if ttl, ok := v.(int); !ok {
return mangos.ErrBadValue
} else if ttl < 1 || ttl > 255 {
Expand Down
2 changes: 1 addition & 1 deletion protocol/surveyor/surveyor.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ func (x *surveyor) GetOption(name string) (interface{}, error) {
}

// NewProtocol returns a new SURVEYOR protocol object.
func NewSurveyor() mangos.Protocol {
func NewProtocol() mangos.Protocol {
return &surveyor{}
}

Expand Down
8 changes: 4 additions & 4 deletions test/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func benchmarkReq(t *testing.B, url string, size int) {
cliopts := make(map[string]interface{})

if strings.HasPrefix(url, "wss://") || strings.HasPrefix(url, "tls+tcp://") {
srvopts[mangos.OptionTlsConfig] = srvCfg
cliopts[mangos.OptionTlsConfig] = cliCfg
srvopts[mangos.OptionTLSConfig] = srvCfg
cliopts[mangos.OptionTLSConfig] = cliCfg
}
srvrdy := make(chan struct{})
srvsock, err := rep.NewSocket()
Expand Down Expand Up @@ -120,8 +120,8 @@ func benchmarkPair(t *testing.B, url string, size int) {
cliopts := make(map[string]interface{})

if strings.HasPrefix(url, "wss://") || strings.HasPrefix(url, "tls+tcp://") {
srvopts[mangos.OptionTlsConfig] = srvCfg
cliopts[mangos.OptionTlsConfig] = cliCfg
srvopts[mangos.OptionTLSConfig] = srvCfg
cliopts[mangos.OptionTLSConfig] = cliCfg
}

finish := make(chan struct{})
Expand Down
12 changes: 6 additions & 6 deletions test/certs.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ var clientTmpl = &x509.Certificate{
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
}

// NewTlsConfig creates a suitable TLS configuration, using
// NewTLSConfig creates a suitable TLS configuration, using
// either a server or client. A self-signed CA Cert is included.
func NewTlsConfig(server bool) (*tls.Config, error) {
func NewTLSConfig(server bool) (*tls.Config, error) {
cfg := &tls.Config{}

keys, err := newKeys()
Expand All @@ -187,20 +187,20 @@ var lock sync.Mutex
var clientConfig *tls.Config
var serverConfig *tls.Config

// GetTlsConfig is like NewTlsConfig, but it caches to avoid regenerating
// GetTLSConfig is like NewTLSConfig, but it caches to avoid regenerating
// key material pointlessly.
func GetTlsConfig(server bool) (*tls.Config, error) {
func GetTLSConfig(server bool) (*tls.Config, error) {
var err error
var cfg *tls.Config
lock.Lock()
if server {
if cfg = serverConfig; cfg == nil {
cfg, err = NewTlsConfig(true)
cfg, err = NewTLSConfig(true)
serverConfig = cfg
}
} else {
if cfg = clientConfig; cfg == nil {
cfg, err = NewTlsConfig(false)
cfg, err = NewTLSConfig(false)
clientConfig = cfg
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/certs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestNewKeys(t *testing.T) {

func TestNewTLSConfig(t *testing.T) {
t.Logf("Creating TLS config")
cfg, err := NewTlsConfig(true)
cfg, err := NewTLSConfig(true)
if err != nil {
t.Errorf("Failed generation: %v", err)
return
Expand Down
8 changes: 4 additions & 4 deletions test/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ import (

var protoReq = req.NewProtocol()
var protoRep = rep.NewProtocol()
var cliCfg, _ = NewTlsConfig(false)
var srvCfg, _ = NewTlsConfig(true)
var cliCfg, _ = NewTLSConfig(false)
var srvCfg, _ = NewTLSConfig(true)

// T is a structure that subtests can inherit from.
type T struct {
Expand Down Expand Up @@ -236,7 +236,7 @@ func (c *T) Dial() bool {
case strings.HasPrefix(c.addr, "tls+tcp://"):
fallthrough
case strings.HasPrefix(c.addr, "wss://"):
options[mangos.OptionTlsConfig] = cliCfg
options[mangos.OptionTLSConfig] = cliCfg
}

err := c.Sock.DialOptions(c.addr, options)
Expand All @@ -255,7 +255,7 @@ func (c *T) Listen() bool {
case strings.HasPrefix(c.addr, "tls+tcp://"):
fallthrough
case strings.HasPrefix(c.addr, "wss://"):
options[mangos.OptionTlsConfig] = srvCfg
options[mangos.OptionTLSConfig] = srvCfg
}
err := c.Sock.ListenOptions(c.addr, options)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion test/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func testDevLoop(t *testing.T, addr string) {

options := make(map[string]interface{})
if strings.HasPrefix(addr, "wss://") || strings.HasPrefix(addr, "tls+tcp://") {
options[mangos.OptionTlsConfig] = srvCfg
options[mangos.OptionTLSConfig] = srvCfg
}

if err := s1.ListenOptions(addr, options); err != nil {
Expand Down
Loading

0 comments on commit cbca8e7

Please sign in to comment.