From c657ba9ae7602c414db8565713b17618c5758fdd Mon Sep 17 00:00:00 2001 From: jan Date: Thu, 13 Oct 2016 17:01:10 +0200 Subject: wenn Init nicht aufgerufen wurde, machen wir in NSA auch nichts. diff --git a/nsa.go b/nsa.go index 827b4e6..0ef6822 100644 --- a/nsa.go +++ b/nsa.go @@ -3,6 +3,7 @@ package nsa import ( "database/sql" "encoding/json" + "errors" "fmt" "os" "strings" @@ -40,6 +41,9 @@ func (l *Logger) getJSON(data interface{}) string { } func (l *Logger) insertEvent(id int, data string) { + if database == nil { + return + } _, err := database.Exec( "INSERT INTO nsa.events (type, data, client_ip) VALUES ($1, $2, $3);", id, data, l.ip) @@ -49,6 +53,9 @@ func (l *Logger) insertEvent(id int, data string) { } func (l *Logger) Log(event string, data interface{}) { + if database == nil { + return + } go func() { id := l.getEventID(event) if id == 0 { @@ -79,6 +86,9 @@ func Init(db *sql.DB) error { } func SetEvents(events []string) error { + if database == nil { + return errors.New("not initialized") + } rows, err := database.Query("SELECT id, name FROM nsa.event_types;") if err != nil { return err -- cgit v0.10.1