// 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 }
// 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 }
// 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 }
// 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 }