semble ok
This commit is contained in:
parent
c363b760d9
commit
9301f353ba
|
@ -66,7 +66,6 @@ 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: '?'}
|
||||
|
||||
|
@ -112,10 +111,12 @@ func (p *CsvParser) Parse(line string) (map[string]string, error) {
|
|||
valueStart = 0
|
||||
}
|
||||
state.delimiter = true
|
||||
field := line[valueStart:index]
|
||||
field := line[valueStart:index +1]
|
||||
field = strings.TrimRight(field,p.delimiters)
|
||||
if state.enclosed {
|
||||
field = strings.TrimRight(strings.TrimLeft(field, string(state.encloserStart)), string(state.encloserEnd))
|
||||
}
|
||||
fmt.Printf("field:%s:\n", field)
|
||||
if currentFieldIndex <= p.maxFieldIndex && p.fields[currentFieldIndex] != p.ignore {
|
||||
ret[p.fields[currentFieldIndex]] = field
|
||||
}
|
||||
|
|
|
@ -73,7 +73,8 @@ 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)
|
||||
|
@ -82,6 +83,7 @@ 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)
|
||||
|
@ -90,13 +92,32 @@ 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