astval

package
v0.0.0-...-eec0033 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package astval provides a set of value types used to serialize configuration data for asterisk phone servers.

Many of the types in this package have an "unspecified" zero value that will not be serialized. This assists with creation of config structures that preserve default values for settings that have not been explicitly set.

Index

Constants

This section is empty.

Variables

View Source
var (
	One  = OneZeroNone(ternaryTrue)
	Zero = OneZeroNone(ternaryFalse)
)

Boolean states for One/Zero.

View Source
var (
	On  = OnOffNone(ternaryTrue)
	Off = OnOffNone(ternaryFalse)
)

Boolean states for On/Off.

View Source
var (
	Yes = YesNoNone(ternaryTrue)
	No  = YesNoNone(ternaryFalse)
)

Boolean states for Yes/No.

Functions

This section is empty.

Types

type Int

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

Int is an integer value.

Its zero value indicates an unspecified condition that will not be marshaled.

func NewInt

func NewInt(value int) Int

NewInt returns an integer with the given value.

func (Int) MarshalAsteriskSetting

func (i Int) MarshalAsteriskSetting(w io.Writer) error

MarshalAsteriskSetting writes the value of i to w.

The value of i will not be written when i is equal to the zero value of Int.

func (*Int) Set

func (i *Int) Set(value int)

Set applies the given value to i.

func (Int) Specified

func (i Int) Specified() bool

Specified returns true if the value of i has been specified.

func (Int) Value

func (i Int) Value() int

Value returns the integer value of i.

type OnOff

type OnOff bool

OnOff is a boolean value that will be marshaled as "on" or "off".

func (OnOff) MarshalText

func (b OnOff) MarshalText() ([]byte, error)

MarshalText marshals the boolean as "on" or "off".

func (OnOff) String

func (b OnOff) String() string

String returns the booelan as the string "on" or "off".

func (*OnOff) UnmarshalText

func (b *OnOff) UnmarshalText(text []byte) error

UnmarshalText parses "on" or "off" as a boolean value.

type OnOffNone

type OnOffNone ternary

OnOffNone is a ternary value that will be marshaled as "on" or "off".

Its zero value indicates an unspecified condition that will not be marshaled.

func (OnOffNone) False

func (t OnOffNone) False() bool

False returns true if t specifies a false value.

func (OnOffNone) MarshalAsteriskSetting

func (t OnOffNone) MarshalAsteriskSetting(w io.Writer) error

MarshalAsteriskSetting writes the value of b to w as "on" or "off".

The value of b will not be written when b is equal to the zero value of OnOff.

func (OnOffNone) MarshalText

func (t OnOffNone) MarshalText() ([]byte, error)

MarshalText marshals the ternary value as "on", "off" or nil.

func (OnOffNone) Specified

func (t OnOffNone) Specified() bool

Specified returns true if t specifies a value.

func (OnOffNone) True

func (t OnOffNone) True() bool

True returns true if t specifies a true value.

func (*OnOffNone) UnmarshalText

func (t *OnOffNone) UnmarshalText(text []byte) error

UnmarshalText parses "on", "off" or "" as a ternary value.

type OneZero

type OneZero bool

OneZero is a boolean value that will be marshaled as "1" or "0".

func (OneZero) MarshalText

func (b OneZero) MarshalText() ([]byte, error)

MarshalText marshals the boolean as "1" or "0".

func (OneZero) String

func (b OneZero) String() string

String returns the booelan as "1" or "0".

func (*OneZero) UnmarshalText

func (b *OneZero) UnmarshalText(text []byte) error

UnmarshalText parses "1" or "0" as a boolean value.

type OneZeroNone

type OneZeroNone ternary

OneZeroNone is a ternary value that will be marshaled as "1" or "0".

Its zero value indicates an unspecified condition that will not be marshaled.

func (OneZeroNone) False

func (t OneZeroNone) False() bool

False returns true if t specifies a false value.

func (OneZeroNone) MarshalAsteriskSetting

func (t OneZeroNone) MarshalAsteriskSetting(w io.Writer) error

MarshalAsteriskSetting writes the value of t to w as "1" or "0".

The value of t will not be written when t is unspecified.

func (OneZeroNone) MarshalText

func (t OneZeroNone) MarshalText() ([]byte, error)

MarshalText marshals the ternary value as "1", "0" or nil.

func (OneZeroNone) Specified

func (t OneZeroNone) Specified() bool

Specified returns true if t specifies a value.

func (OneZeroNone) True

func (t OneZeroNone) True() bool

True returns true if t specifies a true value.

func (*OneZeroNone) UnmarshalText

func (t *OneZeroNone) UnmarshalText(text []byte) error

UnmarshalText parses "1", "0" or "" as a ternary value.

type Seconds

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

Seconds is a time duration that will be marshaled as an integer number of seconds.

Its zero value indicates an unspecified condition that will not be marshaled.

func NewSeconds

func NewSeconds(value time.Duration) Seconds

NewSeconds returns a time duration that will be marshaled as an integer number of seconds.

func (Seconds) MarshalAsteriskSetting

func (seconds Seconds) MarshalAsteriskSetting(w io.Writer) error

MarshalAsteriskSetting writes the value of seconds to w as an integral number of seconds.

The value of seconds will not be written when seconds is equal to the zero value of Seconds.

func (*Seconds) Set

func (seconds *Seconds) Set(value time.Duration)

Set applies the given time duration to seconds.

func (Seconds) Specified

func (seconds Seconds) Specified() bool

Specified returns true if the value of seconds has been specified.

func (Seconds) Value

func (seconds Seconds) Value() time.Duration

Value returns the value of seconds as a duration.

type String

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

String is a string value.

Its zero value indicates an unspecified condition that will not be marshaled.

func NewString

func NewString(value string) String

NewString returns a string with the given value.

func (String) MarshalAsteriskSetting

func (s String) MarshalAsteriskSetting(w io.Writer) error

MarshalAsteriskSetting writes the value of s to w.

The value of s will not be written when s is equal to the zero value of String.

func (*String) Set

func (s *String) Set(value string)

Set applies value to s.

func (String) Specified

func (s String) Specified() bool

Specified returns true if the value of s has been specified.

func (String) Value

func (s String) Value() string

Value returns the string value of s.

type Var

type Var struct {
	Name  string
	Value string
}

Var is an asterisk variable value.

func NewVar

func NewVar(name, value string) Var

NewVar returns a variable value with the given name and value.

func (Var) MarshalText

func (v Var) MarshalText() ([]byte, error)

MarshalText marshals the variable as a string of utf-8 bytes.

func (Var) String

func (v Var) String() string

String returns the variable as a string.

func (*Var) UnmarshalText

func (v *Var) UnmarshalText(text []byte) error

UnmarshalText parses an asterisk variable value from a string of utf-8 bytes.

type YesNo

type YesNo bool

YesNo is a boolean value that will be marshaled as "yes" or "no".

func (YesNo) MarshalText

func (b YesNo) MarshalText() ([]byte, error)

MarshalText marshals the boolean the boolean as "yes" or "no".

func (YesNo) String

func (b YesNo) String() string

String returns the boolean as the string "yes" or "no".

func (*YesNo) UnmarshalText

func (b *YesNo) UnmarshalText(text []byte) error

UnmarshalText parses "yes" or "no" as a boolean value.

type YesNoNone

type YesNoNone ternary

YesNoNone is a ternary value that will be marshaled as "yes" or "no".

Its zero value indicates an unspecified condition that will not be marshaled.

func (YesNoNone) False

func (t YesNoNone) False() bool

False returns true if t specifies a false value.

func (YesNoNone) MarshalAsteriskSetting

func (t YesNoNone) MarshalAsteriskSetting(w io.Writer) error

MarshalAsteriskSetting writes the value of b to w as "on" or "off".

The value of b will not be written when b is equal to the zero value of OnOff.

func (YesNoNone) MarshalText

func (t YesNoNone) MarshalText() ([]byte, error)

MarshalText marshals the ternary value as "on", "off" or nil.

func (YesNoNone) Specified

func (t YesNoNone) Specified() bool

Specified returns true if t specifies a value.

func (YesNoNone) True

func (t YesNoNone) True() bool

True returns true if t specifies a true value.

func (*YesNoNone) UnmarshalText

func (t *YesNoNone) UnmarshalText(text []byte) error

UnmarshalText parses "on", "off" or "" as a ternary value.

Jump to

Keyboard shortcuts

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