Skip to content

Commit

Permalink
golint and govet clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
taotetek committed Dec 7, 2014
1 parent 9bd2aa9 commit 60a2032
Show file tree
Hide file tree
Showing 15 changed files with 240 additions and 219 deletions.
1 change: 0 additions & 1 deletion Makefile
Expand Up @@ -3,7 +3,6 @@ build: format clean test

test: get
go test -v .
go test -v ./zgossip/msg/

bench: get
go test -v -bench . ./...
Expand Down
40 changes: 22 additions & 18 deletions auth.go
Expand Up @@ -6,7 +6,9 @@ package goczmq
#cgo windows LDFLAGS: -L/usr/local/lib -lczmq
#include "czmq.h"
zactor_t *Auth_new () { zactor_t *auth = zactor_new(zauth, NULL); return auth; }
zactor_t *Auth_new () {
zactor_t *auth = zactor_new(zauth, NULL); return auth;
}
*/
import "C"

Expand All @@ -16,94 +18,96 @@ import (

// Auth wraps a CZMQ zauth zactor
type Auth struct {
zactor_t *C.struct__zactor_t
zactorT *C.struct__zactor_t
}

// NewAuth creates a new Auth actor.
func NewAuth() *Auth {
z := &Auth{}
z.zactor_t = C.Auth_new()
z.zactorT = C.Auth_new()
return z
}

// Verbose sets the auth actor to log information to stdout.
func (a *Auth) Verbose() error {
rc := C.zstr_send(unsafe.Pointer(a.zactor_t), C.CString("VERBOSE"))
rc := C.zstr_send(unsafe.Pointer(a.zactorT), C.CString("VERBOSE"))
if rc == -1 {
return ErrActorCmd
}
C.zsock_wait(unsafe.Pointer(a.zactor_t))
C.zsock_wait(unsafe.Pointer(a.zactorT))

return nil
}

// Deny adds an address to a socket's deny list
func (a *Auth) Deny(address string) error {
rc := C.zstr_sendm(unsafe.Pointer(a.zactor_t), C.CString("DENY"))
rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), C.CString("DENY"))
if rc == -1 {
return ErrActorCmd
}

rc = C.zstr_send(unsafe.Pointer(a.zactor_t), C.CString(address))
rc = C.zstr_send(unsafe.Pointer(a.zactorT), C.CString(address))
if rc == -1 {
return ErrActorCmd
}

C.zsock_wait(unsafe.Pointer(a.zactor_t))
C.zsock_wait(unsafe.Pointer(a.zactorT))

return nil
}

// Allow removes a previous Deny
func (a *Auth) Allow(address string) error {
rc := C.zstr_sendm(unsafe.Pointer(a.zactor_t), C.CString("ALLOW"))
rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), C.CString("ALLOW"))
if rc == -1 {
return ErrActorCmd
}

rc = C.zstr_send(unsafe.Pointer(a.zactor_t), C.CString(address))
rc = C.zstr_send(unsafe.Pointer(a.zactorT), C.CString(address))
if rc == -1 {
return ErrActorCmd
}

C.zsock_wait(unsafe.Pointer(a.zactor_t))
C.zsock_wait(unsafe.Pointer(a.zactorT))

return nil
}

// Curve sets auth method to curve
func (a *Auth) Curve(allowed string) error {
rc := C.zstr_sendm(unsafe.Pointer(a.zactor_t), C.CString("CURVE"))
rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), C.CString("CURVE"))
if rc == -1 {
return ErrActorCmd
}

rc = C.zstr_send(unsafe.Pointer(a.zactor_t), C.CString(allowed))
rc = C.zstr_send(unsafe.Pointer(a.zactorT), C.CString(allowed))
if rc == -1 {
return ErrActorCmd
}

C.zsock_wait(unsafe.Pointer(a.zactor_t))
C.zsock_wait(unsafe.Pointer(a.zactorT))

return nil
}

// Plain sets auth method to plain
func (a *Auth) Plain(directory string) error {
rc := C.zstr_sendm(unsafe.Pointer(a.zactor_t), C.CString("PLAIN"))
rc := C.zstr_sendm(unsafe.Pointer(a.zactorT), C.CString("PLAIN"))
if rc == -1 {
return ErrActorCmd
}

rc = C.zstr_send(unsafe.Pointer(a.zactor_t), C.CString(directory))
rc = C.zstr_send(unsafe.Pointer(a.zactorT), C.CString(directory))
if rc == -1 {
return ErrActorCmd
}

C.zsock_wait(unsafe.Pointer(a.zactor_t))
C.zsock_wait(unsafe.Pointer(a.zactorT))

return nil
}

// Destroy destroys the auth actor.
func (a *Auth) Destroy() {
C.zactor_destroy(&a.zactor_t)
C.zactor_destroy(&a.zactorT)
}
8 changes: 4 additions & 4 deletions auth_test.go
Expand Up @@ -36,7 +36,7 @@ func TestAuthIPAllow(t *testing.T) {
// bind the socket and get the port it bound to
port, err := server.Bind("tcp://127.0.0.1:*")
if port <= 0 {
t.Error("port should be > 0, is %d", port)
t.Errorf("port should be > 0, is %d", port)
}

// create a push socket client
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestAuthPlain(t *testing.T) {
// bind the socket and get the port it is bound to
port, err := server.Bind("tcp://127.0.0.1:*")
if port <= 0 {
t.Error("port should be > 0, is %d", port)
t.Errorf("port should be > 0, is %d", port)
}

// create a push client that will use the correct password
Expand Down Expand Up @@ -232,7 +232,7 @@ func TestAuthCurveAllow(t *testing.T) {
// bind the server
port, err := server.Bind("tcp://127.0.0.1:*")
if port <= 0 {
t.Error("port should be > 0, is %d", port)
t.Errorf("port should be > 0, is %d", port)
}

// connect the goodClient
Expand Down Expand Up @@ -344,7 +344,7 @@ func TestAuthCurveCertificate(t *testing.T) {
// bind the server
port, err := server.Bind("tcp://127.0.0.1:*")
if port <= 0 {
t.Error("port should be > 0, is %d", port)
t.Errorf("port should be > 0, is %d", port)
}

// connect the good client
Expand Down
36 changes: 20 additions & 16 deletions beacon.go
Expand Up @@ -6,7 +6,9 @@ package goczmq
#cgo windows LDFLAGS: -L/usr/local/lib -lczmq
#include "czmq.h"
zactor_t *Beacon_new () { zactor_t *beacon = zactor_new(zbeacon, NULL); return beacon; }
zactor_t *Beacon_new () {
zactor_t *beacon = zactor_new(zbeacon, NULL); return beacon;
}
*/
import "C"

Expand All @@ -17,56 +19,58 @@ import (

// Beacon wraps a CZMQ zbeacon zactor
type Beacon struct {
zactor_t *C.struct__zactor_t
zactorT *C.struct__zactor_t
}

// NewBeacon creates a new Beacon instance.
func NewBeacon() *Beacon {
z := &Beacon{}
z.zactor_t = C.Beacon_new()
z.zactorT = C.Beacon_new()
return z
}

// Verbose sets the beacon to log information to stdout.
func (z *Beacon) Verbose() error {
rc := C.zstr_send(unsafe.Pointer(z.zactor_t), C.CString("VERBOSE"))
rc := C.zstr_send(unsafe.Pointer(z.zactorT), C.CString("VERBOSE"))
if rc == -1 {
return ErrActorCmd
}

return nil
}

// Configure accepts a port number and configures the beacon, returning an address
// Configure accepts a port number and configures
// the beacon, returning an address
func (z *Beacon) Configure(port int) (string, error) {
rc := C.zstr_sendm(unsafe.Pointer(z.zactor_t), C.CString("CONFIGURE"))
rc := C.zstr_sendm(unsafe.Pointer(z.zactorT), C.CString("CONFIGURE"))
if rc == -1 {
return "", ErrActorCmd
}

rc = C.zstr_send(unsafe.Pointer(z.zactor_t), C.CString(strconv.Itoa(port)))
rc = C.zstr_send(unsafe.Pointer(z.zactorT), C.CString(strconv.Itoa(port)))
if rc == -1 {
return "", ErrActorCmd
}

Chostname := C.zstr_recv(unsafe.Pointer(z.zactor_t))
Chostname := C.zstr_recv(unsafe.Pointer(z.zactorT))
hostname := C.GoString(Chostname)
return hostname, nil
}

// Publish publishes an announcement at an interval
func (z *Beacon) Publish(announcement string, interval int) error {
rc := C.zstr_sendm(unsafe.Pointer(z.zactor_t), C.CString("PUBLISH"))
rc := C.zstr_sendm(unsafe.Pointer(z.zactorT), C.CString("PUBLISH"))
if rc == -1 {
return ErrActorCmd
}

rc = C.zstr_sendm(unsafe.Pointer(z.zactor_t), C.CString(announcement))
rc = C.zstr_sendm(unsafe.Pointer(z.zactorT), C.CString(announcement))
if rc == -1 {
return ErrActorCmd
}

rc = C.zstr_send(unsafe.Pointer(z.zactor_t), C.CString(strconv.Itoa(interval)))
rc = C.zstr_send(unsafe.Pointer(z.zactorT),
C.CString(strconv.Itoa(interval)))
if rc == -1 {
return ErrActorCmd
}
Expand All @@ -76,12 +80,12 @@ func (z *Beacon) Publish(announcement string, interval int) error {

// Subscribe subscribes to beacons matching the filter
func (z *Beacon) Subscribe(filter string) error {
rc := C.zstr_sendm(unsafe.Pointer(z.zactor_t), C.CString("SUBSCRIBE"))
rc := C.zstr_sendm(unsafe.Pointer(z.zactorT), C.CString("SUBSCRIBE"))
if rc == -1 {
return ErrActorCmd
}

rc = C.zstr_send(unsafe.Pointer(z.zactor_t), C.CString(filter))
rc = C.zstr_send(unsafe.Pointer(z.zactorT), C.CString(filter))
if rc == -1 {
return ErrActorCmd
}
Expand All @@ -91,12 +95,12 @@ func (z *Beacon) Subscribe(filter string) error {

// Recv waits for the specific timeout in milliseconds to receive a beacon
func (z *Beacon) Recv(timeout int) string {
C.zsock_set_rcvtimeo(unsafe.Pointer(z.zactor_t), C.int(timeout))
msg := C.zstr_recv(unsafe.Pointer(z.zactor_t))
C.zsock_set_rcvtimeo(unsafe.Pointer(z.zactorT), C.int(timeout))
msg := C.zstr_recv(unsafe.Pointer(z.zactorT))
return C.GoString(msg)
}

// Destroy destroys the beacon.
func (z *Beacon) Destroy() {
C.zactor_destroy(&z.zactor_t)
C.zactor_destroy(&z.zactorT)
}

0 comments on commit 60a2032

Please sign in to comment.