Documentation ¶
Index ¶
- Constants
- Variables
- func Bytes2Int(val []byte) int
- func Bytes2Map(val []byte) map[string]string
- func Bytes2Slice(val []byte) []string
- func Bytes2SliceForArgs(val []byte) []string
- func Bytes2Str(val []byte) string
- func Colourise(content string, lexer string) (*bytes.Buffer, error)
- func ColouriseBuffer(content *bytes.Buffer, lexer string) error
- func Count(in []byte, selector string, inFormat string) (int, error)
- func Delete(in []byte, selector string, inFormat string, outFormat string) ([]byte, error)
- func DeleteJSON(in []byte, selector string) ([]byte, error)
- func DeleteYaml(in []byte, selector string) ([]byte, error)
- func Find(in []byte, selector string, inFormat string, outFormat string) ([]byte, error)
- func FindJSON(in []byte, selector string) ([]byte, error)
- func FindYaml(in []byte, selector string) ([]byte, error)
- func Load(p ReadParser, reader io.Reader) (interface{}, error)
- func LoadFromFile(filename string, p ReadParser) (interface{}, error)
- func Put(in []byte, selector string, valueType string, value string, inFormat string, ...) ([]byte, error)
- func PutDocument(in []byte, selector string, docs string, inFormat string, outFormat string) ([]byte, error)
- func PutDocumentJSON(in []byte, selector string, docs string) ([]byte, error)
- func PutDocumentYaml(in []byte, selector string, docs string) ([]byte, error)
- func PutJSON(in []byte, selector string, valueType string, value string) ([]byte, error)
- func PutObject(in []byte, selector string, valueTypes []string, kvs []string, inFormat string, ...) ([]byte, error)
- func PutObjectJSON(in []byte, selector string, valueTypes []string, kvs []string) ([]byte, error)
- func PutObjectYaml(in []byte, selector string, valueTypes []string, kvs []string) ([]byte, error)
- func PutYaml(in []byte, selector string, valueType string, value string) ([]byte, error)
- func ResourcesMap2Str(m map[string]string) string
- func Write(p WriteParser, value interface{}, originalValue interface{}, writer io.Writer, ...) error
- type BasicMultiDocument
- type BasicSingleDocument
- type JSONParser
- type MultiDocument
- type OptionKey
- type OriginalRequired
- type Parser
- type PlainParser
- type PutRecord
- type ReadParser
- type ReadWriteOption
- type RealValue
- type SingleDocument
- type TOMLParser
- type UnknownParserErr
- type WriteParser
- type YAMLParser
Constants ¶
const ( // YamlFormat yaml格式 YamlFormat = "yaml" // JSONFormat json格式 JSONFormat = "json" // TomlFormat toml格式 TomlFormat = "toml" // NotFound 记录yaml未找到的key的统一值 NotFound = "__not_found__" )
const ColouriseFormatter = "terminal"
ColouriseFormatter is the formatter used when colourising output.
const ColouriseStyle = "solarized-dark256"
ColouriseStyle is the style used when colourising output.
Variables ¶
var ErrPlainParserNotImplemented = fmt.Errorf("PlainParser.FromBytes not implemented")
ErrPlainParserNotImplemented is returned when you try to use the PlainParser.FromBytes func.
Functions ¶
func Bytes2SliceForArgs ¶
Bytes2SliceForArgs bytes转slice
func ColouriseBuffer ¶
ColouriseBuffer colourises the given buffer in-place.
func Delete ¶
Delete 删除字段,参数inFormat输是入数据解析格式yaml、json 、toml,outFormat是输出数据解析格式yaml、json 、toml,输出格式可以和输入格式不一致
func DeleteJSON ¶ added in v1.3.1
DeleteJSON 删除字段,针对json文档
func DeleteYaml ¶
DeleteYaml 删除字段,针对yaml文档
func Find ¶
Find 查询字段值,select表示选择字段,inFormat输入数据解析格式yaml、json 、toml,outFormat输出数据解析格式yaml、json 、toml,输出格式可以和输入格式不一致
func Load ¶
func Load(p ReadParser, reader io.Reader) (interface{}, error)
Load loads data from the given io.Reader.
func LoadFromFile ¶
func LoadFromFile(filename string, p ReadParser) (interface{}, error)
LoadFromFile loads data from the given file.
func Put ¶
func Put(in []byte, selector string, valueType string, value string, inFormat string, outFormat string) ([]byte, error)
Put 修改或增加一个字段值,inFormat输入数据解析格式yaml、json 、toml,outFormat输出数据解析格式yaml、json 、toml,输出格式可以和输入格式不一致
func PutDocument ¶
func PutDocument(in []byte, selector string, docs string, inFormat string, outFormat string) ([]byte, error)
PutDocument 修改或增加多个字段值,参数docs是yaml或json文档,例如`["foo","bar"] 参数inFormat输是入数据解析格式yaml、json 、toml,outFormat是输出数据解析格式yaml、json 、toml,输出格式可以和输入格式不一致
func PutDocumentJSON ¶ added in v1.3.1
PutDocumentJSON 修改或增加文档,针对json文档
func PutDocumentYaml ¶
PutDocumentYaml 修改或增加文档,针对yaml文档
func PutObject ¶
func PutObject(in []byte, selector string, valueTypes []string, kvs []string, inFormat string, outFormat string) ([]byte, error)
PutObject 修改或增加多个字段值,参数valueTypes是值的类型,kvs是值类型对应kv键值对,例如valueTypes=["int","string"],values=["a=1","b=hello"] 参数inFormat输是入数据解析格式yaml、json 、toml,outFormat是输出数据解析格式yaml、json 、toml,输出格式可以和输入格式不一致
func PutObjectJSON ¶ added in v1.3.1
PutObjectJSON 修改或增加多个字段值,针对json文档
func PutObjectYaml ¶
PutObjectYaml 修改或增加多个字段值,针对yaml文档
func Write ¶
func Write(p WriteParser, value interface{}, originalValue interface{}, writer io.Writer, options ...ReadWriteOption) error
Write writes the value to the given io.Writer.
Types ¶
type BasicMultiDocument ¶
type BasicMultiDocument struct { Values []interface{} // contains filtered or unexported fields }
BasicMultiDocument represents a multi-document file.
func (*BasicMultiDocument) Documents ¶
func (d *BasicMultiDocument) Documents() []interface{}
Documents returns the documents that should be written to output.
func (BasicMultiDocument) OriginalRequired ¶
func (d BasicMultiDocument) OriginalRequired() bool
OriginalRequired tells dasel if the parser requires the original value when converting to bytes.
func (*BasicMultiDocument) RealValue ¶
func (d *BasicMultiDocument) RealValue() interface{}
RealValue returns the real value that dasel should use when processing data.
type BasicSingleDocument ¶
type BasicSingleDocument struct { Value interface{} // contains filtered or unexported fields }
BasicSingleDocument represents a single document file.
func (*BasicSingleDocument) Document ¶
func (d *BasicSingleDocument) Document() interface{}
Document returns the document that should be written to output.
func (BasicSingleDocument) OriginalRequired ¶
func (d BasicSingleDocument) OriginalRequired() bool
OriginalRequired tells dasel if the parser requires the original value when converting to bytes.
func (*BasicSingleDocument) RealValue ¶
func (d *BasicSingleDocument) RealValue() interface{}
RealValue returns the real value that dasel should use when processing data.
type JSONParser ¶
type JSONParser struct { }
JSONParser is a Parser implementation to handle yaml files.
func (*JSONParser) FromBytes ¶
func (p *JSONParser) FromBytes(byteData []byte) (interface{}, error)
FromBytes returns some data that is represented by the given bytes.
func (*JSONParser) ToBytes ¶
func (p *JSONParser) ToBytes(value interface{}, options ...ReadWriteOption) ([]byte, error)
ToBytes returns a slice of bytes that represents the given value.
type MultiDocument ¶
type MultiDocument interface {
Documents() []interface{}
}
MultiDocument is a parser result that contains multiple documents.
type OptionKey ¶
type OptionKey string
OptionKey is a defined type for keys within a ReadWriteOption.
const ( // OptionIndent is the key used with IndentOption. OptionIndent OptionKey = "indent" // OptionPrettyPrint is the key used with PrettyPrintOption. OptionPrettyPrint OptionKey = "prettyPrint" // OptionColourise is the key used with ColouriseOption. OptionColourise OptionKey = "colourise" // OptionEscapeHTML is the key used with EscapeHTMLOption. OptionEscapeHTML OptionKey = "escapeHtml" )
type OriginalRequired ¶
type OriginalRequired interface { // OriginalRequired tells dasel if the parser requires the original value when converting to bytes. OriginalRequired() bool }
OriginalRequired can be used in conjunction with RealValue to allow parsers to be more intelligent with the data they read/write.
type Parser ¶
type Parser interface { ReadParser WriteParser }
Parser can be used to load and save files from/to disk.
type PlainParser ¶
type PlainParser struct { }
PlainParser is a Parser implementation to handle yaml files.
func (*PlainParser) FromBytes ¶
func (p *PlainParser) FromBytes(byteData []byte) (interface{}, error)
FromBytes returns some data that is represented by the given bytes.
func (*PlainParser) ToBytes ¶
func (p *PlainParser) ToBytes(value interface{}, options ...ReadWriteOption) ([]byte, error)
ToBytes returns a slice of bytes that represents the given value.
type PutRecord ¶
type PutRecord struct { Key string `json:"key"` OldVal string `json:"oldVal"` // 如果存在则替换,如果查找的key不存在,则补充统一值__not_found__,表示是新添加 NewVal string `json:"newVal"` }
PutRecord 已成功替换的参数记录
type ReadParser ¶
type ReadParser interface { // FromBytes returns some data that is represented by the given bytes. FromBytes(byteData []byte) (interface{}, error) }
ReadParser can be used to convert bytes to data.
func NewReadParserFromFilename ¶
func NewReadParserFromFilename(filename string) (ReadParser, error)
NewReadParserFromFilename returns a ReadParser from the given filename.
func NewReadParserFromString ¶
func NewReadParserFromString(parser string) (ReadParser, error)
NewReadParserFromString returns a ReadParser from the given parser name.
type ReadWriteOption ¶
type ReadWriteOption struct { Key OptionKey Value interface{} }
ReadWriteOption is an option to be used when writing.
func ColouriseOption ¶
func ColouriseOption(enabled bool) ReadWriteOption
ColouriseOption returns an option that enables or disables colourised output.
func EscapeHTMLOption ¶
func EscapeHTMLOption(enabled bool) ReadWriteOption
EscapeHTMLOption returns an option that enables or disables HTML escaping.
func IndentOption ¶
func IndentOption(indent string) ReadWriteOption
IndentOption returns a write option that sets the given indent.
func PrettyPrintOption ¶
func PrettyPrintOption(enabled bool) ReadWriteOption
PrettyPrintOption returns an option that enables or disables pretty printing.
type RealValue ¶
type RealValue interface {
// RealValue returns the real value that dasel should use when processing data.
RealValue() interface{}
}
RealValue can be used in conjunction with OriginalRequired to allow parsers to be more intelligent with the data they read/write.
type SingleDocument ¶
type SingleDocument interface {
Document() interface{}
}
SingleDocument is a parser result that contains a single document.
type TOMLParser ¶
type TOMLParser struct { }
TOMLParser is a Parser implementation to handle toml files.
func (*TOMLParser) FromBytes ¶
func (p *TOMLParser) FromBytes(byteData []byte) (interface{}, error)
FromBytes returns some data that is represented by the given bytes.
func (*TOMLParser) ToBytes ¶
func (p *TOMLParser) ToBytes(value interface{}, options ...ReadWriteOption) ([]byte, error)
ToBytes returns a slice of bytes that represents the given value.
type UnknownParserErr ¶
type UnknownParserErr struct {
Parser string
}
UnknownParserErr is returned when an invalid parser name is given.
func (UnknownParserErr) Error ¶
func (e UnknownParserErr) Error() string
Error returns the error message.
type WriteParser ¶
type WriteParser interface { // ToBytes returns a slice of bytes that represents the given value. ToBytes(value interface{}, options ...ReadWriteOption) ([]byte, error) }
WriteParser can be used to convert data to bytes.
func NewWriteParserFromFilename ¶
func NewWriteParserFromFilename(filename string) (WriteParser, error)
NewWriteParserFromFilename returns a WriteParser from the given filename.
func NewWriteParserFromString ¶
func NewWriteParserFromString(parser string) (WriteParser, error)
NewWriteParserFromString returns a WriteParser from the given parser name.
type YAMLParser ¶
type YAMLParser struct { }
YAMLParser is a Parser implementation to handle yaml files.
func (*YAMLParser) FromBytes ¶
func (p *YAMLParser) FromBytes(byteData []byte) (interface{}, error)
FromBytes returns some data that is represented by the given bytes.
func (*YAMLParser) ToBytes ¶
func (p *YAMLParser) ToBytes(value interface{}, options ...ReadWriteOption) ([]byte, error)
ToBytes returns a slice of bytes that represents the given value.