Documentation ¶
Index ¶
- Constants
- func EscapeSeparators(s string) string
- func GetSeparator(s string) (string, int, error)
- func Max(x, y int) int
- func UnEscapeSeparators(s string) string
- func Unmarshal(p *Properties, v interface{}) error
- type DiffResult
- type Loader
- type Marshaler
- type MergeOption
- type Properties
- func (p *Properties) Delete(key string)
- func (p *Properties) Diff(m *Properties) DiffResult
- func (p *Properties) Equal(t *Properties) bool
- func (p *Properties) Get(key string) (Property, bool)
- func (p *Properties) Keys() []string
- func (p *Properties) Len() int
- func (p *Properties) MarshalJSON() ([]byte, error)
- func (p *Properties) Merge(m *Properties)
- func (p *Properties) MergeDefaults(m *Properties)
- func (p *Properties) Put(property Property)
- func (p *Properties) Set(key string, value interface{}) error
- func (p *Properties) SetWithComment(key string, value interface{}, comment string) error
- func (p *Properties) Sort()
- func (p *Properties) String() string
- type Property
- func (p Property) Bool() (bool, error)
- func (p *Property) Comment() string
- func (p *Property) Equal(t Property) bool
- func (p Property) Float() (float64, error)
- func (p Property) GetByType(t PropertyType) (interface{}, error)
- func (p Property) Int() (int64, error)
- func (p Property) IsEmpty() bool
- func (p Property) IsValid() bool
- func (p *Property) Key() string
- func (p Property) List() ([]string, error)
- func (p Property) String() string
- func (p *Property) Value() string
- type PropertyType
- type Unmarshaler
Constants ¶
const ( // String containing delimiter characters valid in Java properties Separators = "=: " // Character used for escaping separators EscapeChar = '\\' StructTagKey = "properties" )
const (
// Default delimiter used for exporting Property
DefaultSeparator = "="
)
const (
ListSeparator = ","
)
Variables ¶
This section is empty.
Functions ¶
func EscapeSeparators ¶
EscapeSeparators returns the given s string having the Separators escaped.
func GetSeparator ¶
GetSeparator return the separator character and its index if it is found in the given string. Otherwise an error is returned.
func UnEscapeSeparators ¶
UnEscapeSeparators replaces escaped Separators with their unescaped version in the given string.
func Unmarshal ¶
func Unmarshal(p *Properties, v interface{}) error
Unmarshal updates the values of object pointed by v using the data read from p Properties. If v is nil or not a pointer the Unmarshal returns an error.
If v implements the Unmarshaler interface, Unmarshal calls the UnmarshalProperties method.
Types ¶
type DiffResult ¶
DiffResult is map-like object holding pair of Property object grouped by keys.
func (DiffResult) String ¶
func (d DiffResult) String() string
String returns a human readable representation of DiffResult.
type Marshaler ¶
type Marshaler interface {
MarshalProperties() (*Properties, error)
}
Marshaler is the interface implemented by types that can marshal to Properties by themselves.
type Properties ¶
type Properties struct {
// contains filtered or unexported fields
}
Properties is used to store a group of Property items belong together. It also supports number of operations on the stored Property items.
func Marshal ¶
func Marshal(v interface{}) (*Properties, error)
Marshal returns Properties. If v is nil or not a pointer the Marshal returns an error.
If v implements the Marshaler interface, Marshal calls the MarshalProperties method.
func NewFromFile ¶
func NewFromFile(path string) (*Properties, error)
NewFromFile returns a Properties object containing the data gathered by parsing the file on the given filesystem path.
func NewFromString ¶
func NewFromString(s string) (*Properties, error)
NewFromString returns a Properties object containing the data gathered by parsing the s string.
func NewProperties ¶
func NewProperties() *Properties
NewProperties returns a new and empty Properties object.
func (*Properties) Delete ¶
func (p *Properties) Delete(key string)
Delete the Property with the given name.
func (*Properties) Diff ¶
func (p *Properties) Diff(m *Properties) DiffResult
Diff calculates the difference between p and m Properties and returns a DiffResult holding all the mismatching Keys with their corresponding Property objects.
func (*Properties) Equal ¶
func (p *Properties) Equal(t *Properties) bool
Equal compares two Properties which are equal if they have the same set of Property objects. The order of the keys is not taken into consideration.
func (*Properties) Get ¶
func (p *Properties) Get(key string) (Property, bool)
Get a Property using by its name.
func (*Properties) MarshalJSON ¶
func (p *Properties) MarshalJSON() ([]byte, error)
Provides a custom JSON Marshal interface
func (*Properties) Merge ¶
func (p *Properties) Merge(m *Properties)
Merge two Properties objects by updating Property values in p from m.
func (*Properties) MergeDefaults ¶
func (p *Properties) MergeDefaults(m *Properties)
Merge two Properties objects by updating Property values in p from m if format has a default value
func (*Properties) Put ¶
func (p *Properties) Put(property Property)
Put adds the prop Property to Properties
func (*Properties) Set ¶
func (p *Properties) Set(key string, value interface{}) error
Add a new Property to Properties with the given name and value.
func (*Properties) SetWithComment ¶
func (p *Properties) SetWithComment(key string, value interface{}, comment string) error
Add a new Property to Properties with the given name and value.
func (*Properties) Sort ¶
func (p *Properties) Sort()
func (*Properties) String ¶
func (p *Properties) String() string
String returns string representation of Properties.
type Property ¶
type Property struct {
// contains filtered or unexported fields
}
Property is used to store the key and value for a property. It also provides methods to cast the value of the property into different types.
func (*Property) Equal ¶
Equal checks if the key and value fields for p and t Property objects are the same/equal. It does not take the comment field into the consideration.
func (Property) GetByType ¶
func (p Property) GetByType(t PropertyType) (interface{}, error)
GetByType returns the value of p Property in the requested PropertyType type.
func (Property) List ¶
List converts the value of the Property to a list of strings using the given separator.
type PropertyType ¶
type PropertyType uint8
Supported types for Property
const ( Int PropertyType = iota Float Bool String List Invalid )
type Unmarshaler ¶
type Unmarshaler interface {
UnmarshalProperties(p *Properties) error
}
Unmarshaler is the interface implemented by types that can unmarshal Properties by themselves.