properties

package
v0.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2023 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// String containing delimiter characters valid in Java properties
	Separators = "=: "
	// Character used for escaping separators
	EscapeChar = '\\'

	StructTagKey = "properties"
)
View Source
const (
	// Default delimiter used for exporting Property
	DefaultSeparator = "="
)
View Source
const (
	ListSeparator = ","
)

Variables

This section is empty.

Functions

func EscapeSeparators

func EscapeSeparators(s string) string

EscapeSeparators returns the given s string having the Separators escaped.

func GetSeparator

func GetSeparator(s string) (string, int, error)

GetSeparator return the separator character and its index if it is found in the given string. Otherwise an error is returned.

func Max

func Max(x, y int) int

Max returns the larger of x or y.

func UnEscapeSeparators

func UnEscapeSeparators(s string) string

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

type DiffResult map[string][2]Property

DiffResult is map-like object holding pair of Property object grouped by keys.

func (DiffResult) Keys

func (d DiffResult) Keys() []string

Keys returns a list of keys

func (DiffResult) String

func (d DiffResult) String() string

String returns a human readable representation of DiffResult.

type Loader

type Loader struct {
	// contains filtered or unexported fields
}

func NewLoader

func NewLoader() *Loader

func (*Loader) Load

func (l *Loader) Load(r io.Reader) (*Properties, error)

type Marshaler

type Marshaler interface {
	MarshalProperties() (*Properties, error)
}

Marshaler is the interface implemented by types that can marshal to Properties by themselves.

type MergeOption

type MergeOption uint8
const (
	AllowOverwrite MergeOption = iota
	OnlyDefaults
)

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) Keys

func (p *Properties) Keys() []string

Get list of Property names.

func (*Properties) Len

func (p *Properties) Len() int

Get number of items in Properties

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) Bool

func (p Property) Bool() (bool, error)

Bool converts the Property value to Boolean.

func (*Property) Comment

func (p *Property) Comment() string

Comment returns the comment for the Property.

func (*Property) Equal

func (p *Property) Equal(t Property) bool

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) Float

func (p Property) Float() (float64, error)

Float converts the Property value to Float64.

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) Int

func (p Property) Int() (int64, error)

Int converts the Property value to Int64.

func (Property) IsEmpty

func (p Property) IsEmpty() bool

IsEmpty returns true if either the key or the value fields are empty.

func (Property) IsValid

func (p Property) IsValid() bool

IsValid returns true if Property key is a non-empty string.

func (*Property) Key

func (p *Property) Key() string

Key method return the name of the Property.

func (Property) List

func (p Property) List() ([]string, error)

List converts the value of the Property to a list of strings using the given separator.

func (Property) String

func (p Property) String() string

String implements the Stringer interface.

func (*Property) Value

func (p *Property) Value() string

Value returns the value of the Property.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL