Exemple #1
0
func (grok *Grok) Match(str string) (map[string]string, error) {

	var gm C.grok_match_t
	//log.Print("Attemping to match '", str, "'")

	grok.lock.Lock()
	ret := C.grok_exec(grok.grok, C.CString(str), &gm)
	grok.lock.Unlock()
	if ret != C.GROK_OK {
		return nil, GrokError{ret}
	}

	var pdata, pname *C.char
	var pname_len, pdata_len C.int

	result := make(map[string]string)

	grok.lock.Lock()
	C.grok_match_walk_init(&gm)
	for C.grok_match_walk_next(&gm, &pname, &pname_len, &pdata, &pdata_len) == 0 {
		name := C.GoStringN(pname, pname_len)
		data := C.GoStringN(pdata, pdata_len)

		result[name] = data
	}
	C.grok_match_walk_end(&gm)
	grok.lock.Unlock()
	return result, nil

	//grok_match_t
}
Exemple #2
0
func (grok *Grok) Match(text string) *Match {
	t := C.CString(text)

	var cmatch C.grok_match_t

	ret := C.grok_exec(grok.g, t, &cmatch)
	if ret != GROK_OK {
		return nil
	}

	match := new(Match)
	match.gm = cmatch

	return match
}
Exemple #3
0
/* Note that Matches must be freed after use, to free the C string
   used for matching and the PCRE vector */
func (grok *Grok) Match(text string) *Match {
	t := C.CString(text)

	var cmatch C.grok_match_t

	ret := C.grok_exec(grok.g, t, &cmatch)
	if ret != GROK_OK {
		C.free(unsafe.Pointer(t))
		return nil
	}

	match := new(Match)
	match.gm = cmatch
	match.grok = grok
	match.subject = text
	return match
}