Documentation ¶
Overview ¶
Copyright (c) 2022 Thomas Ziegler <thomas.zglr@googlemail.com>. All rights reserved.
Licensed under the MIT License ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2022 Thomas Ziegler <thomas.zglr@googlemail.com>. All rights reserved.
Licensed under the MIT License ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2022 Thomas Ziegler <thomas.zglr@googlemail.com>. All rights reserved.
Licensed under the MIT License ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2022 Thomas Ziegler <thomas.zglr@googlemail.com>. All rights reserved.
Licensed under the MIT License ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Copyright (c) 2022 Thomas Ziegler <thomas.zglr@googlemail.com>. All rights reserved.
Licensed under the MIT License ¶
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Index ¶
- Constants
- func CanHandleValue(value any) bool
- func FindChain(in interface{}, byChain ...string) (data interface{}, err error)
- func IsPointer(i interface{}) bool
- type DataReader
- type JsonReader
- func (j *JsonReader) FileDecode(path string, decodeInterface interface{}) (err error)
- func (j *JsonReader) GetFields() *StructDef
- func (j *JsonReader) HaveFields() bool
- func (j *JsonReader) Marshal(in interface{}) (out []byte, err error)
- func (j *JsonReader) SupportsExt() []string
- func (j *JsonReader) Unmarshal(in []byte, out interface{}) (err error)
- type ReflectTagRef
- type StructDef
- func (s *StructDef) AddToIndex(field ...string)
- func (s *StructDef) DetectIndentCount(withField string) int
- func (s *StructDef) GetField(field string) (StructField, error)
- func (s *StructDef) GetFieldByTag(tag string) (StructField, error)
- func (s *StructDef) GetOrderedIndexSlice() []string
- func (s *StructDef) ReadStruct(tagparser reftagFunc) error
- func (s *StructDef) ResetIndexSlice()
- func (s *StructDef) SetAllowedTagSearch(allow bool)
- func (s *StructDef) SetIndexSlice(slice []string)
- func (s *StructDef) SetMaxIdentDiff(diff int) *StructDef
- type StructField
- type Yamc
- func (y *Yamc) Delete(key string)
- func (y *Yamc) FindValue(path string) (content any, err error)
- func (y *Yamc) Get(key string) (interface{}, bool)
- func (y *Yamc) GetData() map[string]interface{}
- func (y *Yamc) GetGjsonString(path string) (jsonStr string, err error)
- func (y *Yamc) GetOrSet(key string, data interface{}) (interface{}, bool)
- func (y *Yamc) GetSourceDataType() int
- func (y *Yamc) Gjson(path string) (gjson.Result, error)
- func (y *Yamc) IsLoaded() bool
- func (y *Yamc) Parse(use DataReader, in []byte) error
- func (y *Yamc) Range(f func(key, value interface{}) bool)
- func (y *Yamc) Reset()
- func (y *Yamc) SetData(data map[string]interface{})
- func (y *Yamc) Store(key string, data interface{})
- func (y *Yamc) ToString(use DataReader) (str string, err error)
- func (y *Yamc) Update(key string, f func(value interface{}) interface{}) bool
- type YamlReader
- func (y *YamlReader) FileDecode(path string, decodeInterface interface{}) (err error)
- func (y *YamlReader) GetFields() *StructDef
- func (y *YamlReader) HaveFields() bool
- func (y *YamlReader) Marshal(in interface{}) (out []byte, err error)
- func (y *YamlReader) SupportsExt() []string
- func (y *YamlReader) Unmarshal(in []byte, out interface{}) (err error)
Constants ¶
const ( TYPE_ARRAY = 1 // source type []interface{} TYPE_STRING_MAP = 2 // ... map[string]interface{} UNSET = 0 // initial status )
Variables ¶
This section is empty.
Functions ¶
func CanHandleValue ¶
CanHandleValue just make sure we do not run in panic because of an dataype we nor able to handle
Types ¶
type DataReader ¶
type DataReader interface { Unmarshal(in []byte, out interface{}) (err error) // Unmarshal is used to decode the data Marshal(in interface{}) (out []byte, err error) // Marshal is used to encode the data FileDecode(path string, decodeInterface interface{}) (err error) // FileDecode is used to decode the data from a file SupportsExt() []string // SupportsExt returns a list of supported file extensions HaveFields() bool // HaveFields returns true if the data reader have fields they can report GetFields() *StructDef // GetFields returns the fields of the data reader }
DataReader is the interface for the data reader the data reader have to support the regular unmarshal and marshal. additionally it have to support the file decode. the filedecode is as shortcut for read the file and decode it. this part of the interface is used to get the data from the file depending on the file extension. for this, the SupportsExt returns a list of supported file extensions.
the HaveFields is used to tell the caller if the data reader have fields they can report. this can be used to work with data tags for validateing data. depending on the type of the source structure, it is not guaranteed that the data reader have fields they can report. if we have fields to report, read them with GetFields.
type JsonReader ¶
type JsonReader struct {
// contains filtered or unexported fields
}
func NewJsonReader ¶
func NewJsonReader() *JsonReader
func (*JsonReader) FileDecode ¶
func (j *JsonReader) FileDecode(path string, decodeInterface interface{}) (err error)
func (*JsonReader) GetFields ¶
func (j *JsonReader) GetFields() *StructDef
func (*JsonReader) HaveFields ¶
func (j *JsonReader) HaveFields() bool
func (*JsonReader) Marshal ¶
func (j *JsonReader) Marshal(in interface{}) (out []byte, err error)
func (*JsonReader) SupportsExt ¶
func (j *JsonReader) SupportsExt() []string
func (*JsonReader) Unmarshal ¶
func (j *JsonReader) Unmarshal(in []byte, out interface{}) (err error)
type ReflectTagRef ¶
type StructDef ¶
type StructDef struct { // if true, the struct is initialized Init bool // the struct we want to read Struct interface{} // the fields of the struct Fields map[string]StructField // if the struct is ignored, we store the reason here IgnoredBecauseOf string // contains filtered or unexported fields }
func NewStructDef ¶
func NewStructDef(strct interface{}) *StructDef
NewStructDef returns a new struct reader
func (*StructDef) AddToIndex ¶
func (*StructDef) DetectIndentCount ¶
check the index entries and calculate the indent level we need to find the indent level to be able to read the struct
func (*StructDef) GetField ¶
func (s *StructDef) GetField(field string) (StructField, error)
GetField returns the field information for the given field name if the field name contains a dot, we try to find the child
func (*StructDef) GetFieldByTag ¶
func (s *StructDef) GetFieldByTag(tag string) (StructField, error)
func (*StructDef) GetOrderedIndexSlice ¶
func (*StructDef) ReadStruct ¶
ReadStruct reads the given struct and returns a map with all values the tagparser is a function that can be used to parse the tag by an specialized data reader, so the reader can solve the tag. the tagparser can be nil, if you don't need it.
func (*StructDef) ResetIndexSlice ¶
func (s *StructDef) ResetIndexSlice()
func (*StructDef) SetAllowedTagSearch ¶
SetAllowedTagSearch allows to search for fields by tag. example: Username string `json:"username"` will be found by "username" and "Username". This is disabled by default, because it is slower but the only way to find fields if we have the tags only.
func (*StructDef) SetIndexSlice ¶
func (*StructDef) SetMaxIdentDiff ¶
SetMaxIdentDiff sets the max ident diff. the default is 1. if you have a json struct, you might to set this to 2 depending if you have a json struct like this:
Targets: { Labels: [ "payed", "not payed", "important", "not important", ], Worker: [ { Name: "hello", SureName: "world", },
because of the json format, the ident level is once added for objects in lists. depends on the list tag [ followed by the object tag {. note: depending on formating of course.
type StructField ¶
type StructField struct { // the name of the field Name string // the path of the field in relation to the struct Path string // the type of the field Type string // the tag of the field Tag reflect.StructTag // reader depending... OrginalTag ReflectTagRef // if we are a node, we have children Children map[string]StructField // for faster access store the amount of children ChildLen int }
type Yamc ¶
type Yamc struct {
// contains filtered or unexported fields
}
func NewByFile ¶
func NewByFile(filename string, rdr DataReader) (*Yamc, error)
NewByFile loads file content and returns a new Ymac
func (*Yamc) FindValue ¶
GetGjsonString returns the content of the path as json string result or the error while processing the data
func (*Yamc) GetData ¶
GetData is just the getter for the actual data. this is independend if they are loaded or not
func (*Yamc) GetGjsonString ¶
GetGjsonString returns the content of the path as json string result or the error while processing the data
func (*Yamc) GetOrSet ¶
GetOrSet is just a wrapper for the sync.Map LoadOrStore function The bool result is true if the value was loaded, false if stored.
func (*Yamc) GetSourceDataType ¶
GetSourceDataType returns the flag what tells us how the sourece was stuctured yamc.TYPE_ARRAY = []interface{} yamc.TYPE_STRING_MAP = map[string]interface{} yamc.UNSET = current nothing is loaded. so we have no type
func (*Yamc) Gjson ¶
Gson wrapps gson and rerurns the gsonResult or the error while using Marshall the data into json what can be used by gson
func (*Yamc) IsLoaded ¶
IsLoaded returns the loaded flag. this is not the same as having data it just means it is read without having errors
func (*Yamc) Parse ¶
func (y *Yamc) Parse(use DataReader, in []byte) error
Parse is wrapping the Unmarshal for json and yaml. because the default format is map[string]interface{} it fallback to read []interface{} and convert them.
func (*Yamc) SetData ¶
setData reset current data and set new data by apply the map[string]interface{} to the sync.Map
type YamlReader ¶
type YamlReader struct {
// contains filtered or unexported fields
}
YamlReader is a reader for yaml files
func (*YamlReader) FileDecode ¶
func (y *YamlReader) FileDecode(path string, decodeInterface interface{}) (err error)
FileDecode decodes a yaml file into a struct
func (*YamlReader) GetFields ¶
func (y *YamlReader) GetFields() *StructDef
GetFields returns the field information
func (*YamlReader) HaveFields ¶
func (y *YamlReader) HaveFields() bool
HaveFields returns true if the reader has field information
func (*YamlReader) Marshal ¶
func (y *YamlReader) Marshal(in interface{}) (out []byte, err error)
Marshal marshals like yaml.Marshal
func (*YamlReader) SupportsExt ¶
func (y *YamlReader) SupportsExt() []string
func (*YamlReader) Unmarshal ¶
func (y *YamlReader) Unmarshal(in []byte, out interface{}) (err error)
Unmarshal unmarshals like yaml.Unmarshal