Compare commits
No commits in common. "master" and "v0.0.11" have entirely different histories.
|
@ -14,9 +14,7 @@ type CsvParser struct {
|
|||
ignore string
|
||||
maxFieldIndex int
|
||||
}
|
||||
func (p *csvParser) FieldCount() int {
|
||||
return maxFieldIndex + 1
|
||||
}
|
||||
|
||||
/*
|
||||
* delimiters: string with all delimiter chars
|
||||
* mergeDelimiters: if true, all successive delimiters are considered as one
|
||||
|
@ -68,6 +66,7 @@ type ParserState struct {
|
|||
func (p *CsvParser) Parse(line string) (map[string]string, error) {
|
||||
currentFieldIndex := 0
|
||||
valueStart := -1
|
||||
//valueEnd := -1
|
||||
|
||||
state := ParserState{inField: false, delimiter: true, escape: false, enclosed: false, enclosedMode: false, encloserStart: '?', encloserEnd: '?'}
|
||||
|
||||
|
@ -113,8 +112,7 @@ func (p *CsvParser) Parse(line string) (map[string]string, error) {
|
|||
valueStart = 0
|
||||
}
|
||||
state.delimiter = true
|
||||
field := line[valueStart : index+1]
|
||||
field = strings.TrimRight(field, p.delimiters)
|
||||
field := line[valueStart:index]
|
||||
if state.enclosed {
|
||||
field = strings.TrimRight(strings.TrimLeft(field, string(state.encloserStart)), string(state.encloserEnd))
|
||||
}
|
||||
|
|
|
@ -73,8 +73,7 @@ func TestCorrectLines(t *testing.T) {
|
|||
t.Fatalf("Parsing of empty line failed %v %v", err, event)
|
||||
}
|
||||
fmt.Println("event is", event)
|
||||
/*
|
||||
csvParser.Initialize(" \t", true, []string{"\"\"", "[]"}, "ignore ignore ignore proxy ignore domain clientip ignore ignore apache-date request status bytes duration referer user-agent", "ignore")
|
||||
|
||||
line = "Aug 7 00:00:00 proxy-4 haproxy[17429]: www.yvelines.gouv.fr 66.249.64.10 - - [06/Aug/2024:23:59:59 +0200] \"GET /content/download/19274/117923/file/SE_EAU_20190325_LesJardines_78201900027_LetNotifCompletude+recepisse.pdf HTTP/1.1\" 301 1414 240 \"\" \"Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.182 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)\" \"-\" \"GB\" 15169"
|
||||
fmt.Println("parsing:", line)
|
||||
event, err = csvParser.Parse(line)
|
||||
|
@ -83,7 +82,6 @@ func TestCorrectLines(t *testing.T) {
|
|||
}
|
||||
fmt.Println("event is", event)
|
||||
|
||||
csvParser.Initialize(" \t", true, []string{"\"\"", "[]"}, "ignore ignore ignore proxy ignore domain clientip ignore ignore apache-date request status bytes duration referer user-agent", "ignore")
|
||||
line = "Aug 7 00:00:00 proxy-4 haproxy[17429]: www.yvelines.gouv.fr 66.249.64.10 - - [06/Aug/2024:23:59:59 +0200] \"GET /content/download/19274/117923/file/SE_EAU_20190325_LesJardines_78201900027_LetNotifCompletude+recepisse.pdf HTTP/1.1\" 301 1414 240 \"\" \"Mozilla/5.0 (Linux; Android 6.0.1; Nexus 5X Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.6478.182 Mobile Safari/537.36 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)\" \"-\" \"GB\" \"15169"
|
||||
fmt.Println("parsing:", line)
|
||||
event, err = csvParser.Parse(line)
|
||||
|
@ -92,32 +90,4 @@ func TestCorrectLines(t *testing.T) {
|
|||
}
|
||||
fmt.Println("event is", event)
|
||||
|
||||
csvParser.Initialize(" ", true, []string{"\"\""}, "verb uri http-version", "ignore")
|
||||
line = "GET /Actions-de-l-Etat/Vos-aides/Particuliers/Pass-culture?_escaped_fragment_=/particuliers/page/R65575 HTTP/1.1"
|
||||
fmt.Println("parsing:", line)
|
||||
event, err = csvParser.Parse(line)
|
||||
if err != nil {
|
||||
t.Fatalf("Parsing of empty line failed %v %v", err, event)
|
||||
}
|
||||
fmt.Println("event is", event)
|
||||
*/
|
||||
csvParser.Initialize(" ", true, []string{"\"\""}, "verb uri http-version", "ignore")
|
||||
line = "GET /Actions-de-l-Etat/Vos-aides/Particuliers/Pass-culture?_escaped_fragment_=/particuliers/page/R65575 HTTP/1.1"
|
||||
fmt.Println("parsing:", line)
|
||||
event, err = csvParser.Parse(line)
|
||||
if err != nil {
|
||||
t.Fatalf("Parsing of empty line failed %v %v", err, event)
|
||||
}
|
||||
fmt.Println("event is", event)
|
||||
|
||||
csvParser.Initialize(" ", true, []string{"\"\""}, "verb uri http-version", "ignore")
|
||||
line = "G"
|
||||
fmt.Println("parsing:", line)
|
||||
event, err = csvParser.Parse(line)
|
||||
if err != nil {
|
||||
t.Fatalf("Parsing of empty line failed %v %v", err, event)
|
||||
}
|
||||
fmt.Println("event is", event)
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue