Skip to content

Commit 761dfdd

Browse files
committed
SCFF-21 created the constructor method
1 parent 696cbc7 commit 761dfdd

1 file changed

Lines changed: 50 additions & 73 deletions

File tree

sumo-log4go/sumoLogicAppender.go

Lines changed: 50 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,69 @@
11
package sumoLogicAppender
22

3-
import(
3+
import (
4+
"bufio"
5+
"bytes"
46
"net/http"
5-
"net/url"
6-
"bytes"
7-
"log"
8-
"io/ioutil"
9-
"time"
10-
"bitbucket.org/mcplusa-ondemand/firehouse-to-sumologic/eventRouting"
11-
7+
"time"
128
)
139

14-
type sumoLogicAppender struct{
15-
string url = nil
16-
int connectionTimeout = 1000
17-
//int socketTimeout = 60000
18-
http.Client httpClient = nil
19-
}
20-
21-
// setUrl receives a pointer to sumoLogicAppender so it can modify it.
22-
func (s *sumoLogicAppender) setUrl(string url) {
23-
s.url = url
10+
type SumoLogicAppender struct {
11+
url string
12+
connectionTimeout int //10000
13+
httpClient http.Client
2414
}
2515

26-
// connectionTimeout receives a pointer to sumoLogicAppender so it can modify it.
27-
func (s *sumoLogicAppender) connectionTimeout(int connectionTimeout) {
28-
s.connectionTimeout = connectionTimeout
29-
}
30-
31-
// socketTimeout receives a pointer to sumoLogicAppender so it can modify it.
32-
func (s *sumoLogicAppender) socketTimeout(int socketTimeout) {
33-
s.socketTimeout = socketTimeout
16+
func newSumoLogicAppender(urlValue string, connectionTimeoutValue int) *SumoLogicAppender {
17+
return &SumoLogicAppender{
18+
url: urlValue,
19+
connectionTimeout: connectionTimeoutValue,
20+
httpClient: http.Client{Timeout: time.Duration(connectionTimeoutValue * int(time.Millisecond))},
21+
}
3422
}
3523

3624
func (boolean) isInitialized() {
37-
return httpClient != nil;
38-
}
39-
40-
func activateOptions(){
41-
httpClient := {
42-
Timeout: connectionTimeout * time.Millisecod,
43-
}
25+
return httpClient != nil
4426
}
4527

46-
47-
func append(Event event){
48-
if !checkEntryConditions() {
49-
return
50-
}
51-
var buffer bytes.Buffer
52-
buffer.WriteString(event)
53-
reader := bufio.NewReader(resp.Body)
54-
for {
55-
line, err := reader.ReadBytes('\n')
56-
//...
57-
//log.Println(string(line))
58-
}
59-
60-
61-
sendToSumo(buffer.String())
28+
func append(Event map[string]interface{}, Message string) {
29+
if !checkEntryConditions() {
30+
return
31+
}
32+
var buffer bytes.Buffer
33+
buffer.WriteString(event)
34+
reader := bufio.NewReader(resp.Body)
35+
for {
36+
line, err := reader.ReadBytes('\n')
37+
//...
38+
//log.Println(string(line))
39+
}
40+
41+
sendToSumo(buffer.String())
6242
}
6343

6444
func (boolean) checkEntryConditions() {
65-
if httpClient==nil {
66-
return false
67-
}
68-
return true
45+
if httpClient == nil {
46+
return false
47+
}
48+
return true
6949
}
7050

71-
72-
func senToSumo(string log){
73-
if !checkEntryConditions() {
74-
return
75-
}
76-
request, err := http.NewRequest("POST", url, bytes.NewBufferString(log))
77-
//request.SetBasicAuth("admin", "admin")
78-
response, err := httpClient.Do(request)
79-
if !err {
80-
if response.StatusCode !=200 {
81-
//log print "Received HTTP error from Sumo Service:"
82-
}
83-
//consume the body if you want to re-use the connection
84-
}else{
85-
log.Fatal(err)
86-
}
87-
defer response.Body.Close()
51+
func senToSumo(log string) {
52+
if !checkEntryConditions() {
53+
return
54+
}
55+
request, err := http.NewRequest("POST", url, bytes.NewBufferString(log))
56+
//request.SetBasicAuth("admin", "admin")
57+
response, err := httpClient.Do(request)
58+
if !err {
59+
jghjk
60+
if response.StatusCode != 200 {
61+
//log print "Received HTTP error from Sumo Service:"
62+
}
63+
//consume the body if you want to re-use the connection
64+
} else {
65+
log.Fatal(err)
66+
}
67+
defer response.Body.Close()
8868

8969
}
90-
91-
92-

0 commit comments

Comments
 (0)