@@ -17,10 +17,9 @@ type Event struct {
1717 Source string `json:"source" binding:"required"` // app name
1818 SourceType string `json:"sourcetype" binding:"required"` // Splunk bucket to group logs in
1919 Index string `json:"index" binding:"required"` // idk what it does..
20- Event map [ string ] string `json:"event" binding:"required"` // throw any useful key/val pairs here
20+ Event interface {} `json:"event" binding:"required"` // throw any useful key/val pairs here
2121}
2222
23-
2423// Client manages communication with Splunk's HTTP Event Collector.
2524// New client objects should be created using the NewClient function.
2625//
@@ -55,7 +54,7 @@ func NewClient(httpClient *http.Client, URL string, Token string, Source string,
5554
5655// NewEvent creates a new log event to send to Splunk.
5756// This should be the primary way a Splunk log object is constructed, and is automatically called by the Log function attached to the client.
58- func NewEvent (event map [ string ] string , source string , sourcetype string , index string ) (Event ) {
57+ func NewEvent (event interface {} , source string , sourcetype string , index string ) (Event ) {
5958 hostname , _ := os .Hostname ()
6059 e := Event {Time : time .Now ().Unix (), Host : hostname , Source : source , SourceType : sourcetype , Index : index , Event : event }
6160
@@ -67,7 +66,7 @@ func NewEvent(event map[string]string, source string, sourcetype string, index s
6766// All that must be provided for a log event are the desired map[string]string key/val pairs. These can be anything
6867// that provide context or information for the situation you are trying to log (i.e. err messages, status codes, etc).
6968// The function auto-generates the event timestamp and hostname for you.
70- func (c * Client ) Log (event map [ string ] string ) (error ) {
69+ func (c * Client ) Log (event interface {} ) (error ) {
7170 // create Splunk log
7271 log := NewEvent (event , c .Source , c .SourceType , c .Index )
7372
@@ -94,15 +93,15 @@ func (c *Client) Log(event map[string]string) (error) {
9493 // If statusCode is not good, return error string
9594 switch res .StatusCode {
9695 case 200 :
96+ return nil
9797 default :
9898 // Turn response into string and return it
9999 buf := new (bytes.Buffer )
100100 buf .ReadFrom (res .Body )
101101 responseBody := buf .String ()
102102 err = errors .New (responseBody )
103103
104- //log.Print(responseBody) // print error to screen for checking/debugging
105104 }
106-
105+ //log.Print(responseBody) // print error to screen for checking/debugging
107106 return err
108107}
0 commit comments