示例#1
0
func (match *Match) Captures() map[string][]string {
	captures := make(map[string][]string)

	var name, substring *C.char
	var namelen, sublen C.int

	C.grok_match_walk_init(&match.gm)

	for C.grok_match_walk_next(&match.gm, &name, &namelen, &substring, &sublen) == GROK_OK {
		var substrings []string

		gname := C.GoStringN(name, namelen)
		gsubstring := C.GoStringN(substring, sublen)

		if val := captures[gname]; val == nil {
			substrings = make([]string, 0)
		} else {
			substrings = val
		}

		captures[gname] = append(substrings, gsubstring)
	}
	C.grok_match_walk_end(&match.gm)

	return captures
}
示例#2
0
文件: grok.go 项目: rckclmbr/gogrok
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
}
示例#3
0
/* Start an iterator for the match results. The iterator must be free'd when no longer in use.
   Each match has state for one iterator, multiple concurrent iterators are not supported. */
func (match *Match) StartIterator() {
	C.grok_match_walk_init(&match.gm)
}