Browse Source

fix: Minor fixes and reformatting

Matthias Ladkau 4 years ago
parent
commit
cb63692f97

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+.cache
+.cover
+coverage.txt
+coverage.out
+coverage.html

+ 1 - 1
cryptutil/stringcrypt_test.go

@@ -45,7 +45,7 @@ func TestStringEncryption(t *testing.T) {
 		return
 		return
 	}
 	}
 
 
-	decString, err = DecryptString("foo1", "bar")
+	_, err = DecryptString("foo1", "bar")
 	if err.Error() != "Ciphertext is too short - must be at least: 16" {
 	if err.Error() != "Ciphertext is too short - must be at least: 16" {
 		t.Error(err)
 		t.Error(err)
 		return
 		return

+ 2 - 2
datautil/persistentmap_test.go

@@ -64,7 +64,7 @@ func TestPersistentMap(t *testing.T) {
 
 
 	pm.Flush()
 	pm.Flush()
 
 
-	pm2, err := LoadPersistentMap(testdbdir + "/testmap.map")
+	pm2, _ := LoadPersistentMap(testdbdir + "/testmap.map")
 
 
 	if len(pm2.Data) != 2 {
 	if len(pm2.Data) != 2 {
 		t.Error("Unexpected size of map")
 		t.Error("Unexpected size of map")
@@ -112,7 +112,7 @@ func TestPersistentStringMap(t *testing.T) {
 
 
 	pm.Flush()
 	pm.Flush()
 
 
-	pm2, err := LoadPersistentStringMap(testdbdir + "/teststringmap.map")
+	pm2, _ := LoadPersistentStringMap(testdbdir + "/teststringmap.map")
 
 
 	if len(pm2.Data) != 2 {
 	if len(pm2.Data) != 2 {
 		t.Error("Unexpected size of map")
 		t.Error("Unexpected size of map")

+ 1 - 1
datautil/ringbuffer_test.go

@@ -109,7 +109,7 @@ EEE`[1:] {
 	rb.Reset()
 	rb.Reset()
 
 
 	if !rb.IsEmpty() {
 	if !rb.IsEmpty() {
-		t.Error("Buffer shoudl be empty after a reset")
+		t.Error("Buffer should be empty after a reset")
 		return
 		return
 	}
 	}
 }
 }

+ 5 - 5
defs/rambazamba/eventsource.go

@@ -1,25 +1,25 @@
 /*
 /*
- * Rambazamba
+ * Brawler
  *
  *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
+ * Copyright 2019 Matthias Ladkau. All rights reserved.
  *
  *
  * This Source Code Form is subject to the terms of the MIT
  * This Source Code Form is subject to the terms of the MIT
  * License, If a copy of the MIT License was not distributed with this
  * License, If a copy of the MIT License was not distributed with this
  * file, You can obtain one at https://opensource.org/licenses/MIT.
  * file, You can obtain one at https://opensource.org/licenses/MIT.
  */
  */
 
 
-package rambazamba
+package brawler
 
 
 /*
 /*
 EventPublisher is the API for external event sources to publish events
 EventPublisher is the API for external event sources to publish events
-to Rambazamba engines. The event source should use a given EventPublisher
+to Brawler engines. The event source should use a given EventPublisher
 object to inject events. Use api.RegisterEventSource to create a new
 object to inject events. Use api.RegisterEventSource to create a new
 EventPublisher object.
 EventPublisher object.
 */
 */
 type EventPublisher interface {
 type EventPublisher interface {
 
 
 	/*
 	/*
-		AddEvent adds a new event to one or more Rambazamba engines.
+		AddEvent adds a new event to one or more Brawler engines.
 		Expects 3 parameters: Name - a name which identifies the event,
 		Expects 3 parameters: Name - a name which identifies the event,
 		Kind - an event kind which is checked against the kind match of
 		Kind - an event kind which is checked against the kind match of
 		sinks and State - an event state which contains additional data.
 		sinks and State - an event state which contains additional data.

+ 3 - 3
defs/rumble/func.go

@@ -1,7 +1,7 @@
 /*
 /*
- * Rambazamba
+ * Brawler
  *
  *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
+ * Copyright 2019 Matthias Ladkau. All rights reserved.
  *
  *
  * This Source Code Form is subject to the terms of the MIT
  * This Source Code Form is subject to the terms of the MIT
  * License, If a copy of the MIT License was not distributed with this
  * License, If a copy of the MIT License was not distributed with this
@@ -10,7 +10,7 @@
 
 
 /*
 /*
 Package rumble contains all definitions which external code should use to
 Package rumble contains all definitions which external code should use to
-integrate with Rambazamba.
+integrate with Brawler.
 */
 */
 package rumble
 package rumble
 
 

+ 2 - 2
defs/rumble/globals.go

@@ -1,7 +1,7 @@
 /*
 /*
- * Rambazamba
+ * Brawler
  *
  *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
+ * Copyright 2019 Matthias Ladkau. All rights reserved.
  *
  *
  * This Source Code Form is subject to the terms of the MIT
  * This Source Code Form is subject to the terms of the MIT
  * License, If a copy of the MIT License was not distributed with this
  * License, If a copy of the MIT License was not distributed with this

+ 2 - 2
defs/rumble/runtime.go

@@ -1,7 +1,7 @@
 /*
 /*
- * Rambazamba
+ * Brawler
  *
  *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
+ * Copyright 2019 Matthias Ladkau. All rights reserved.
  *
  *
  * This Source Code Form is subject to the terms of the MIT
  * This Source Code Form is subject to the terms of the MIT
  * License, If a copy of the MIT License was not distributed with this
  * License, If a copy of the MIT License was not distributed with this

+ 2 - 2
defs/rumble/variables.go

@@ -1,7 +1,7 @@
 /*
 /*
- * Rambazamba
+ * Brawler
  *
  *
- * Copyright 2016 Matthias Ladkau. All rights reserved.
+ * Copyright 2019 Matthias Ladkau. All rights reserved.
  *
  *
  * This Source Code Form is subject to the terms of the MIT
  * This Source Code Form is subject to the terms of the MIT
  * License, If a copy of the MIT License was not distributed with this
  * License, If a copy of the MIT License was not distributed with this

+ 6 - 4
fileutil/multifilebuffer.go

@@ -71,7 +71,7 @@ func NewMultiFileBuffer(filename string, it FilenameIterator, cond RolloverCondi
 
 
 	}
 	}
 
 
-	return mfb, nil
+	return mfb, err
 }
 }
 
 
 /*
 /*
@@ -96,9 +96,11 @@ func (mfb *MultiFileBuffer) Write(output []byte) (int, error) {
 
 
 		}
 		}
 
 
-		mfb.lock.Lock()
-		b, err = mfb.fp.Write(output)
-		mfb.lock.Unlock()
+		if err == nil {
+			mfb.lock.Lock()
+			b, err = mfb.fp.Write(output)
+			mfb.lock.Unlock()
+		}
 	}
 	}
 
 
 	return b, err
 	return b, err

+ 1 - 1
fileutil/multifilebuffer_test.go

@@ -275,7 +275,7 @@ func TestMultiFileBufferSimpleNumbering(t *testing.T) {
 
 
 	// Create a new buffer
 	// Create a new buffer
 
 
-	buf, err = NewMultiFileBuffer(filename,
+	buf, _ = NewMultiFileBuffer(filename,
 		ConsecutiveNumberIterator(3), SizeBasedRolloverCondition(4))
 		ConsecutiveNumberIterator(3), SizeBasedRolloverCondition(4))
 
 
 	for i := 0; i < 4; i++ {
 	for i := 0; i < 4; i++ {

+ 4 - 3
fileutil/zip.go

@@ -66,12 +66,13 @@ func UnzipReader(reader io.ReaderAt, size int64, dest string, overwrite bool) er
 					}
 					}
 
 
 					if err = os.MkdirAll(fdir, os.ModePerm); err == nil {
 					if err = os.MkdirAll(fdir, os.ModePerm); err == nil {
-						f, err := os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
+						var file *os.File
+						file, err = os.OpenFile(fpath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, f.Mode())
 
 
 						if err == nil {
 						if err == nil {
-							_, err = io.Copy(f, rc)
+							_, err = io.Copy(file, rc)
 
 
-							f.Close()
+							file.Close()
 						}
 						}
 					}
 					}
 				}
 				}

+ 1 - 1
httputil/access/acl_test.go

@@ -502,7 +502,7 @@ Users:
 
 
 	pt.table = nil
 	pt.table = nil
 
 
-	// Now do the same excercise again but with syncing from memory
+	// Now do the same exercise again but with syncing from memory
 
 
 	if err := pt.sync(false); err != nil {
 	if err := pt.sync(false); err != nil {
 		t.Error(err)
 		t.Error(err)

+ 3 - 0
httputil/auth/auth_test.go

@@ -12,6 +12,7 @@ import (
 	"sync"
 	"sync"
 	"testing"
 	"testing"
 
 
+	"devt.de/krotik/common/errorutil"
 	"devt.de/krotik/common/httputil"
 	"devt.de/krotik/common/httputil"
 	"devt.de/krotik/common/httputil/user"
 	"devt.de/krotik/common/httputil/user"
 )
 )
@@ -113,6 +114,8 @@ func sendTestRequest(url string, method string, headers map[string]string,
 		req, err = http.NewRequest(method, url, nil)
 		req, err = http.NewRequest(method, url, nil)
 	}
 	}
 
 
+	errorutil.AssertOk(err)
+
 	// Add headers
 	// Add headers
 
 
 	req.Header.Set("Content-Type", "application/json")
 	req.Header.Set("Content-Type", "application/json")

+ 2 - 2
httputil/auth/cookie_test.go

@@ -114,7 +114,7 @@ func TestCookieAuth(t *testing.T) {
 
 
 	// Login request
 	// Login request
 
 
-	res, resp = sendTestRequest(TESTQUERYURL+"/login", "GET", map[string]string{
+	_, resp = sendTestRequest(TESTQUERYURL+"/login", "GET", map[string]string{
 		"user1": "yams",
 		"user1": "yams",
 		"pass1": "yams",
 		"pass1": "yams",
 	}, nil, nil)
 	}, nil, nil)
@@ -228,7 +228,7 @@ func TestCookieAuth(t *testing.T) {
 
 
 	// Wrong credentials - error message depends on custom handler
 	// Wrong credentials - error message depends on custom handler
 
 
-	res, resp = sendTestRequest(TESTQUERYURL+"/login", "GET", map[string]string{
+	_, resp = sendTestRequest(TESTQUERYURL+"/login", "GET", map[string]string{
 		"user1": "yams",
 		"user1": "yams",
 		"pass1": "yams1",
 		"pass1": "yams1",
 	}, nil, nil)
 	}, nil, nil)

+ 2 - 2
httputil/httpserver_test.go

@@ -238,7 +238,7 @@ func sendTestRequest() string {
 	url := "http://localhost" + testporthttp + "/httpserver_test"
 	url := "http://localhost" + testporthttp + "/httpserver_test"
 
 
 	var jsonStr = []byte(`{"msg":"Hello!"}`)
 	var jsonStr = []byte(`{"msg":"Hello!"}`)
-	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
+	req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
 	req.Header.Set("X-Custom-Header", "myvalue")
 	req.Header.Set("X-Custom-Header", "myvalue")
 	req.Header.Set("Content-Type", "application/json")
 	req.Header.Set("Content-Type", "application/json")
 
 
@@ -273,7 +273,7 @@ func sendTestHTTPSRequest(caCert string) string {
 	url := "https://localhost" + testporthttps + "/httpsserver_test"
 	url := "https://localhost" + testporthttps + "/httpsserver_test"
 
 
 	var jsonStr = []byte(`{"msg":"Hello!"}`)
 	var jsonStr = []byte(`{"msg":"Hello!"}`)
-	req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
+	req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr))
 	req.Header.Set("X-Custom-Header", "myvalue")
 	req.Header.Set("X-Custom-Header", "myvalue")
 	req.Header.Set("Content-Type", "application/json")
 	req.Header.Set("Content-Type", "application/json")
 
 

+ 3 - 0
httputil/user/user_test.go

@@ -12,6 +12,7 @@ import (
 	"sync"
 	"sync"
 	"testing"
 	"testing"
 
 
+	"devt.de/krotik/common/errorutil"
 	"devt.de/krotik/common/httputil"
 	"devt.de/krotik/common/httputil"
 )
 )
 
 
@@ -105,6 +106,8 @@ func sendTestRequest(url string, method string, headers map[string]string,
 		req, err = http.NewRequest(method, url, nil)
 		req, err = http.NewRequest(method, url, nil)
 	}
 	}
 
 
+	errorutil.AssertOk(err)
+
 	// Add headers
 	// Add headers
 
 
 	req.Header.Set("Content-Type", "application/json")
 	req.Header.Set("Content-Type", "application/json")

+ 12 - 10
lang/graphql/parser/parser.go

@@ -431,7 +431,7 @@ represented by an optional fragment name, a type condition and a selection set.
 */
 */
 func ndFragmentDefinition(p *parser, self *ASTNode) (*ASTNode, error) {
 func ndFragmentDefinition(p *parser, self *ASTNode) (*ASTNode, error) {
 	var err error
 	var err error
-	var current = p.node
+	var current *ASTNode
 
 
 	if p.node.Token.ID == TokenName {
 	if p.node.Token.ID == TokenName {
 
 
@@ -460,18 +460,20 @@ func ndFragmentDefinition(p *parser, self *ASTNode) (*ASTNode, error) {
 		} else {
 		} else {
 			p.node, err = p.next()
 			p.node, err = p.next()
 
 
-			if p.node.Token.ID == TokenName {
+			if err == nil {
+				if p.node.Token.ID == TokenName {
 
 
-				// Append the fragment name
+					// Append the fragment name
 
 
-				changeAstNode(p.node, NodeTypeCondition, p)
-				self.Children = append(self.Children, p.node)
-				p.node, err = p.next()
+					changeAstNode(p.node, NodeTypeCondition, p)
+					self.Children = append(self.Children, p.node)
+					p.node, err = p.next()
 
 
-			} else {
+				} else {
 
 
-				err = p.newParserError(ErrNameExpected,
-					p.node.Token.String(), *p.node.Token)
+					err = p.newParserError(ErrNameExpected,
+						p.node.Token.String(), *p.node.Token)
+				}
 			}
 			}
 		}
 		}
 	}
 	}
@@ -751,7 +753,7 @@ ndDirectives parses a directive expression. (@spec 2.12)
 */
 */
 func ndDirectives(p *parser, self *ASTNode) (*ASTNode, error) {
 func ndDirectives(p *parser, self *ASTNode) (*ASTNode, error) {
 	var err error
 	var err error
-	var current = p.node
+	var current *ASTNode
 
 
 	dir := newAstNode(NodeDirective, p, p.node.Token)
 	dir := newAstNode(NodeDirective, p, p.node.Token)
 
 

+ 1 - 1
pools/threadpool.go

@@ -38,7 +38,7 @@ type Task interface {
 	Run() error
 	Run() error
 
 
 	/*
 	/*
-		HandleError handles an error which occured during the run method.
+		HandleError handles an error which occurred during the run method.
 	*/
 	*/
 	HandleError(e error)
 	HandleError(e error)
 }
 }

+ 2 - 2
sortutil/heap.go

@@ -48,7 +48,7 @@ func (h *IntHeap) Peek() int {
 }
 }
 
 
 /*
 /*
-RemoveFirst removes the first occurences of item r from the IntHeap.
+RemoveFirst removes the first occurrences of item r from the IntHeap.
 */
 */
 func (h *IntHeap) RemoveFirst(r int) {
 func (h *IntHeap) RemoveFirst(r int) {
 	heapList := *h
 	heapList := *h
@@ -67,7 +67,7 @@ func (h *IntHeap) RemoveFirst(r int) {
 }
 }
 
 
 /*
 /*
-RemoveAll removes all occurences of item r from the IntHeap.
+RemoveAll removes all occurrences of item r from the IntHeap.
 */
 */
 func (h *IntHeap) RemoveAll(r int) {
 func (h *IntHeap) RemoveAll(r int) {
 	newHeap := &IntHeap{}
 	newHeap := &IntHeap{}

+ 41 - 39
termutil/getch/util_linux.go

@@ -82,66 +82,68 @@ func attachReader() (getch, error) {
 
 
 						err = ioctl(gl.out.Fd(), syscall.TCGETS, &gl.origTios)
 						err = ioctl(gl.out.Fd(), syscall.TCGETS, &gl.origTios)
 
 
-						// Reconfigure terminal attributes - see Linux termios
+						if err == nil {
+							// Reconfigure terminal attributes - see Linux termios
 
 
-						tios := gl.origTios
+							tios := gl.origTios
 
 
-						// Unsetting the following input mode flags means:
+							// Unsetting the following input mode flags means:
 
 
-						// IGNBRK Don't ignore BREAK condition on input
-						// BRKINT Breaks don't cause SIGINT to be send and read as \0
-						// PARMRK Bytes with parity or framing errors are not marked
-						// ISTRIP Do not strip off the eighth bit
-						// INLCR Do not translate newline to carriage return on input
-						// IGNCR No not ignore carriage return on input
-						// ICRNL Do not translate carriage return to newline on input
-						// IXON Do not enable XON/XOFF flow control on input
+							// IGNBRK Don't ignore BREAK condition on input
+							// BRKINT Breaks don't cause SIGINT to be send and read as \0
+							// PARMRK Bytes with parity or framing errors are not marked
+							// ISTRIP Do not strip off the eighth bit
+							// INLCR Do not translate newline to carriage return on input
+							// IGNCR No not ignore carriage return on input
+							// ICRNL Do not translate carriage return to newline on input
+							// IXON Do not enable XON/XOFF flow control on input
 
 
-						tios.Iflag &^= syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK |
-							syscall.ISTRIP | syscall.INLCR | syscall.IGNCR |
-							syscall.ICRNL | syscall.IXON
+							tios.Iflag &^= syscall.IGNBRK | syscall.BRKINT | syscall.PARMRK |
+								syscall.ISTRIP | syscall.INLCR | syscall.IGNCR |
+								syscall.ICRNL | syscall.IXON
 
 
-						// Unsetting the following local mode flags means:
+							// Unsetting the following local mode flags means:
 
 
-						// ECHO Do not echo input characters
-						// ECHONL Do not echo newline characters
-						// ICANON Do not operate in canonical mode - i.e. no line buffering
-						// ISIG Do not generate signals when receiving either INTR, QUIT,
-						//      SUSP, or DSUSP characters
-						// IEXTEN Do not enable implementation-defined input processing
+							// ECHO Do not echo input characters
+							// ECHONL Do not echo newline characters
+							// ICANON Do not operate in canonical mode - i.e. no line buffering
+							// ISIG Do not generate signals when receiving either INTR, QUIT,
+							//      SUSP, or DSUSP characters
+							// IEXTEN Do not enable implementation-defined input processing
 
 
-						tios.Lflag &^= syscall.ECHO | syscall.ECHONL | syscall.ICANON |
-							syscall.ISIG | syscall.IEXTEN
+							tios.Lflag &^= syscall.ECHO | syscall.ECHONL | syscall.ICANON |
+								syscall.ISIG | syscall.IEXTEN
 
 
-						// Unsetting the following control mode flags means:
+							// Unsetting the following control mode flags means:
 
 
-						// CSIZE Clear any character size mask
-						// PARENB Do not enable parity generation on output and
-						//        parity checking for input
+							// CSIZE Clear any character size mask
+							// PARENB Do not enable parity generation on output and
+							//        parity checking for input
 
 
-						tios.Cflag &^= syscall.CSIZE | syscall.PARENB
+							tios.Cflag &^= syscall.CSIZE | syscall.PARENB
 
 
-						// Set character size mask 8 bit
+							// Set character size mask 8 bit
 
 
-						tios.Cflag |= syscall.CS8
+							tios.Cflag |= syscall.CS8
 
 
-						// Set minimum number of characters for noncanonical read
+							// Set minimum number of characters for noncanonical read
 
 
-						tios.Cc[syscall.VMIN] = 1
+							tios.Cc[syscall.VMIN] = 1
 
 
-						// Set timeout in deciseconds for noncanonical read
+							// Set timeout in deciseconds for noncanonical read
 
 
-						tios.Cc[syscall.VTIME] = 0
+							tios.Cc[syscall.VTIME] = 0
 
 
-						err = ioctl(gl.out.Fd(), syscall.TCSETS, &tios)
+							err = ioctl(gl.out.Fd(), syscall.TCSETS, &tios)
 
 
-						if err == nil {
+							if err == nil {
 
 
-							// All is well we can start listening for events
+								// All is well we can start listening for events
 
 
-							go gl.eventListener()
+								go gl.eventListener()
 
 
-							return gl, nil
+								return gl, nil
+							}
 						}
 						}
 					}
 					}
 				}
 				}

+ 2 - 2
termutil/term.go

@@ -27,13 +27,13 @@ import (
 KeyHandler handles specific key events. KeyHandlers are used to extend the
 KeyHandler handles specific key events. KeyHandlers are used to extend the
 functionality of the normal ConsoleLineTerminal. Returns if the event was
 functionality of the normal ConsoleLineTerminal. Returns if the event was
 consumed (no further handling possible), a new input buffer and any errors
 consumed (no further handling possible), a new input buffer and any errors
-that might have occured. The new input buffer is ignored if it is nil.
+that might have occurred. The new input buffer is ignored if it is nil.
 */
 */
 type KeyHandler func(*getch.KeyEvent, []rune) (bool, []rune, error)
 type KeyHandler func(*getch.KeyEvent, []rune) (bool, []rune, error)
 
 
 /*
 /*
 ConsoleLineTerminal is the most common console terminal implementation. The
 ConsoleLineTerminal is the most common console terminal implementation. The
-user types input and a choosen backend records the input by key. It has a
+user types input and a chosen backend records the input by key. It has a
 graceful fallback to a standard line reader for all other platforms. The
 graceful fallback to a standard line reader for all other platforms. The
 functionality can be extended by adding key handlers.
 functionality can be extended by adding key handlers.
 
 

+ 0 - 2
timeutil/timeutil_test.go

@@ -53,8 +53,6 @@ func TestTimestamp(t *testing.T) {
 
 
 	// Test compare
 	// Test compare
 
 
-	ts = MakeTimestamp()
-
 	if res, err := CompareTimestamp("1475602478271", "1475615168232"); res != 1 || err != nil {
 	if res, err := CompareTimestamp("1475602478271", "1475615168232"); res != 1 || err != nil {
 		t.Error("Unexpected compare result:", res, err)
 		t.Error("Unexpected compare result:", res, err)
 		return
 		return