示例#1
0
// LoadRules retrieves a compiled ruleset from filename.
func LoadRules(filename string) (*Rules, error) {
	var yrRules *C.YR_RULES
	cfilename := C.CString(filename)
	defer C.free(unsafe.Pointer(cfilename))
	if err := newError(C.yr_rules_load(cfilename, &yrRules)); err != nil {
		return nil, err
	}
	r := &Rules{rules: &rules{cptr: yrRules}}
	runtime.SetFinalizer(r.rules, (*rules).finalize)
	return r, nil
}
示例#2
0
func LoadFromFile(path string) (*Rules, error) {
	var handle *C.YR_RULES

	cpath := C.CString(path)
	code := C.yr_rules_load(cpath, &handle)
	C.free(unsafe.Pointer(cpath))

	if code != C.ERROR_SUCCESS {
		return nil, Error(code)
	}

	return &Rules{
		handle: handle,
	}, nil
}