Exemple #1
0
// AddOpenFile reads in the configuration from a file already opened using os.Open
// or a related function.
func (p *Parser) AddOpenFile(f *os.File) error {
	fd := f.Fd()
	result := C.ucl_parser_add_fd(p.parser, C.int(fd))
	if !result {
		errstr := C.ucl_parser_get_error(p.parser)
		return errors.New(C.GoString(errstr))
	}
	return nil
}
Exemple #2
0
// SetFileVariables sets the standard file variables ($FILENAME and $CURDIR) based
// on the provided filepath. If the argument expand is true, the path will be expanded
// out to an absolute path
//
// For example, if the current directory is /etc/nginx, and you give a path of
// ../file.conf, with exand = false, $FILENAME = ../file.conf and $CURDIR = ..,
// while with expand = true, $FILENAME = /etc/file.conf and $CURDIR = /etc
func (p *Parser) SetFileVariables(filepath string, expand bool) error {
	cpath := C.CString(filepath)
	defer C.free(unsafe.Pointer(cpath))
	result := C.ucl_parser_set_filevars(p.parser, cpath, C.bool(expand))
	if !result {
		errstr := C.ucl_parser_get_error(p.parser)
		return errors.New(C.GoString(errstr))
	}
	return nil
}
Exemple #3
0
// AddFile adds a file to parse.
func (p *Parser) AddFile(path string) error {
	cs := C.CString(path)
	defer C.free(unsafe.Pointer(cs))

	result := C.ucl_parser_add_file(p.parser, cs)
	if !result {
		errstr := C.ucl_parser_get_error(p.parser)
		return errors.New(C.GoString(errstr))
	}
	return nil
}
Exemple #4
0
// AddString adds a string data to parse.
func (p *Parser) AddString(data string) error {
	cs := C.CString(data)
	defer C.free(unsafe.Pointer(cs))

	result := C.ucl_parser_add_string(p.parser, cs, C.size_t(len(data)))
	if !result {
		errstr := C.ucl_parser_get_error(p.parser)
		return errors.New(C.GoString(errstr))
	}
	return nil
}