Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Remove un-necessary comments
  • Loading branch information
glinton committed Mar 16, 2018
1 parent 58439c1 commit dc7d37e
Show file tree
Hide file tree
Showing 16 changed files with 2 additions and 78 deletions.
1 change: 0 additions & 1 deletion README.md
Expand Up @@ -188,7 +188,6 @@ import (
"github.com/nanopack/mist/clients"
)

//
func main() {
client, err := clients.New("127.0.0.1:1445")
if err != nil {
Expand Down
5 changes: 0 additions & 5 deletions clients/clients_test.go
Expand Up @@ -23,7 +23,6 @@ func TestMain(m *testing.M) {

server.StartTCP(testAddr, nil)

//
os.Exit(m.Run())
}

Expand All @@ -36,7 +35,6 @@ func TestTCPClientConnect(t *testing.T) {
}
defer client.Close()

//
if err := client.Ping(); err != nil {
t.Fatalf("ping failed")
}
Expand All @@ -59,7 +57,6 @@ func TestBadTCPClientConnect(t *testing.T) {
}
defer client.Close()

//
if err := client.Ping(); err != nil {
t.Fatalf("ping failed")
}
Expand All @@ -74,8 +71,6 @@ func TestBadTCPClientConnect(t *testing.T) {
// are already tested in other tests (proxy_test and subscriptions_test in the
// core package)
func TestTCPClient(t *testing.T) {

//
client, err := clients.New(testAddr, "")
if err != nil {
t.Fatalf("failed to connect - %s", err.Error())
Expand Down
2 changes: 0 additions & 2 deletions commands/list.go
Expand Up @@ -10,8 +10,6 @@ import (
)

var (

//
listCmd = &cobra.Command{
Hidden: true,
Use: "listall",
Expand Down
2 changes: 0 additions & 2 deletions commands/ping.go
Expand Up @@ -10,8 +10,6 @@ import (
)

var (

//
pingCmd = &cobra.Command{
Use: "ping",
Short: "Ping a running mist server",
Expand Down
2 changes: 1 addition & 1 deletion commands/publish.go
Expand Up @@ -48,7 +48,7 @@ var (
}
)

var data string //
var data string

// init
func init() {
Expand Down
1 change: 0 additions & 1 deletion commands/subscribe.go
Expand Up @@ -41,7 +41,6 @@ func subscribe(ccmd *cobra.Command, args []string) error {
return err
}

//
if err := client.Subscribe(tags); err != nil {
fmt.Printf("Unable to subscribe - %s\n", err.Error())
return fmt.Errorf("")
Expand Down
2 changes: 0 additions & 2 deletions commands/who.go
Expand Up @@ -10,8 +10,6 @@ import (
)

var (

//
whoCmd = &cobra.Command{
Hidden: true,
Use: "who",
Expand Down
7 changes: 0 additions & 7 deletions core/mist_test.go
Expand Up @@ -14,17 +14,13 @@ var (

// BenchmarkPublish
func BenchmarkPublish(b *testing.B) {

//
p := NewProxy()
defer p.Close()

//
p.Subscribe([]string{"a"})

b.ResetTimer()

//
for i := 0; i < b.N; i++ {
p.Publish([]string{"a"}, testMsg)
}
Expand All @@ -33,21 +29,18 @@ func BenchmarkPublish(b *testing.B) {
// TestPublish tests that the publish Publish method publishes to all subscribers
func TestPublish(t *testing.T) {

//
p1 := NewProxy()
defer p1.Close()

p2 := NewProxy()
defer p2.Close()

//
p1.Subscribe([]string{"a"})
p2.Subscribe([]string{"a"})

// have mist publish the message
Publish([]string{"a"}, testMsg)

//
verifyMessage(testMsg, p1, t)
verifyMessage(testMsg, p2, t)

Expand Down
3 changes: 0 additions & 3 deletions core/proxy.go
Expand Up @@ -48,7 +48,6 @@ func (p *Proxy) connect() {
go p.handleMessages()
}

//
func (p *Proxy) handleMessages() {

defer func() {
Expand All @@ -57,7 +56,6 @@ func (p *Proxy) handleMessages() {
close(p.Pipe) // don't close pipe (response/pong messages need it), but leaving it unclosed leaves ram bloat on server even after client disconnects
}()

//
for {
select {

Expand All @@ -76,7 +74,6 @@ func (p *Proxy) handleMessages() {
p.Pipe <- msg
}

//
case <-p.done:
return
}
Expand Down
13 changes: 0 additions & 13 deletions core/proxy_test.go
Expand Up @@ -5,7 +5,6 @@ import "testing"
// TestSameSubscriber tests to ensure that mist will not send message to the
// same proxy who publishes them
func TestSameSubscriber(t *testing.T) {

// create a new proxy
sender := NewProxy()
defer sender.Close()
Expand All @@ -25,12 +24,9 @@ func TestSameSubscriber(t *testing.T) {
// TestDifferentSubscriber tests to ensure that mist will send messages
// to another subscribed proxy, and then not send when unsubscribed.
func TestDifferentSubscriber(t *testing.T) {

//
sender := NewProxy()
defer sender.Close()

//
receiver := NewProxy()
defer receiver.Close()

Expand All @@ -50,20 +46,15 @@ func TestDifferentSubscriber(t *testing.T) {
// TestManySubscribers tests to ensure that mist will send messages to many
// subscribers of the same tags, and then not send once unsubscribed
func TestManySubscribers(t *testing.T) {

//
sender := NewProxy()
defer sender.Close()

//
r1 := NewProxy()
defer r1.Close()

//
r2 := NewProxy()
defer r2.Close()

//
r3 := NewProxy()
defer r3.Close()

Expand Down Expand Up @@ -92,7 +83,6 @@ func TestManySubscribers(t *testing.T) {
// subscriptions
func TestListSubscriptions(t *testing.T) {

//
sender := NewProxy()
defer sender.Close()

Expand Down Expand Up @@ -145,12 +135,9 @@ func TestListSubscriptions(t *testing.T) {
// tags. It tests that multiple tags are received only as subscribed, and that
// multiple tags aren't receieved once unsubscribed.
func TestTags(t *testing.T) {

//
sender := NewProxy()
defer sender.Close()

//
receiver := NewProxy()
defer receiver.Close()

Expand Down
3 changes: 0 additions & 3 deletions core/subscription_test.go
Expand Up @@ -79,7 +79,6 @@ func TestEmptySubscription(t *testing.T) {
func TestAddRemoveSimple(t *testing.T) {
node := newNode()

//
node.Add([]string{"a"})
if len(node.ToSlice()) != 1 {
t.Fatalf("Failed to add node")
Expand Down Expand Up @@ -197,13 +196,11 @@ func TestMatchSimple(t *testing.T) {
t.Fatalf("Expected match!")
}

//
node.Add([]string{"a", "b"})
if !node.Match([]string{"a", "b"}) {
t.Fatalf("Expected match!")
}

//
node.Add([]string{"a", "b", "c"})
if !node.Match([]string{"a", "b", "c"}) {
t.Fatalf("Expected match!")
Expand Down
9 changes: 0 additions & 9 deletions core/subscriptions.go
Expand Up @@ -20,22 +20,18 @@ type (
}
)

//
func newNode() (node *Node) {

node = &Node{
branches: map[string]*Node{},
leaves: map[string]struct{}{},
}

//
return
}

// Add sorts the keys and then attempts to add them
func (node *Node) Add(keys []string) {

//
if len(keys) == 0 {
return
}
Expand Down Expand Up @@ -71,7 +67,6 @@ func (node *Node) add(keys []string) {
// Remove sorts the keys and then attempts to remove them
func (node *Node) Remove(keys []string) {

//
if len(keys) == 0 {
return
}
Expand All @@ -82,7 +77,6 @@ func (node *Node) Remove(keys []string) {

// remove ...
func (node *Node) remove(keys []string) {

// if there is only one key remaining we are at the end of the chain and need
// to remove just the leaf
if len(keys) == 1 {
Expand Down Expand Up @@ -117,8 +111,6 @@ func (node *Node) Match(keys []string) bool {

// ​match ...
func (node *Node) match(keys []string) bool {

//
if len(keys) == 0 {
return false
}
Expand All @@ -145,7 +137,6 @@ func (node *Node) match(keys []string) bool {
// ToSlice recurses down an entire node returning a list of all branches and leaves
// as a slice of slices
func (node *Node) ToSlice() (list [][]string) {

// iterate through each leaf appending it as a slice to the list of keys
for leaf := range node.leaves {
list = append(list, []string{leaf})
Expand Down
1 change: 0 additions & 1 deletion main.go
@@ -1,4 +1,3 @@
//
package main

import (
Expand Down
4 changes: 0 additions & 4 deletions server/http.go
Expand Up @@ -9,7 +9,6 @@ import (
)

var (

// Router ...
Router = pat.New()
)
Expand All @@ -32,7 +31,6 @@ func StartHTTPS(uri string, errChan chan<- error) {
errChan <- ErrNotImplemented
}

//
func newHTTP(address string) error {
lumber.Info("HTTP server listening at '%s'...\n", address)

Expand All @@ -42,8 +40,6 @@ func newHTTP(address string) error {

// routes registers all api routes with the router
func routes() *pat.Router {

//
Router.Get("/ping", func(rw http.ResponseWriter, req *http.Request) {
rw.Write([]byte("pong\n"))
})
Expand Down
22 changes: 1 addition & 21 deletions server/server.go
Expand Up @@ -3,32 +3,24 @@ package server
import (
"fmt"
"net/url"
// "strings"
"sync"
"time"

"github.com/jcelliott/lumber"
// "github.com/spf13/viper"

"github.com/nanopack/mist/auth"
// "github.com/nanopack/mist/core"
)

//
var (
ErrNotImplemented = fmt.Errorf("Error: Not Implemented\n")

// this is a map of the supported servers that can be started by mist
servers = map[string]handleFunc{}
// handlers = map[string]mist.HandleFunc{}

servers = map[string]handleFunc{}
serversTex sync.RWMutex
// handlersTex sync.RWMutex{}

authtoken string // used when determining if auth command handlers should be added
)

//
type (
handleFunc func(uri string, errChan chan<- error)
)
Expand All @@ -44,18 +36,6 @@ func Register(name string, auth handleFunc) {
// listeners; the listeners provided is a comma delimited list of uri strings
// (scheme:[//[user:pass@]host[:port]][/]path[?query][#fragment])
func Start(uris []string, token string) error {

// // BUG: https://github.com/spf13/viper/issues/112
// // due to the above issue with cobra/viper (pflag) when --listeners are provided
// // we have to parse this string slice manually and then split it into the slice
// // of string schemes it should have been in the first place; one day this bug
// // will get fixed and this will probably break... at that point this should be
// // removed
// if viper.GetString("config") == "" {
// r := strings.NewReplacer("[", "", "]", "")
// uris = strings.Split(r.Replace(uris[0]), ",")
// }

// check to see if a token is provided; an authenticator cannot work without
// a token and so it should error here informing that.
if auth.IsConfigured() && token == "" {
Expand Down
3 changes: 0 additions & 3 deletions server/websocket.go
Expand Up @@ -69,7 +69,6 @@ func StartWS(uri string, errChan chan<- error) {
// auth commands are added
if auth.IsConfigured() && !proxy.Authenticated {

//
var xtoken string
switch {
case req.Header.Get("X-AUTH-TOKEN") != "":
Expand Down Expand Up @@ -191,8 +190,6 @@ func StartWSS(uri string, errChan chan<- error) {
// if an authenticator was passed, check for a token on connect to see if
// auth commands are added
if auth.IsConfigured() && !proxy.Authenticated {

//
var xtoken string
switch {
case req.Header.Get("X-AUTH-TOKEN") != "":
Expand Down

0 comments on commit dc7d37e

Please sign in to comment.