Documentation
¶
Overview ¶
Package attributes provides types that can represent explicitly set values, including the zero values of their stored types, to enable HTTP requests to account for all intended parameter values.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func UnmarshalJSONForNamedParametersCollections ¶
UnmarshalJSONForNamedParametersCollections unmarshals JSON data into the given dest interface. dest must be a pointer to a struct, and any struct fields with the "named_parameters_collection" tag must be of the NamedParametersCollection type.
This method exists to enable unmarshaling of the same level of a JSON document to a struct and also to NamedParametersCollection fields of the same struct.
func UnmarshalJSONForParameters ¶
UnmarshalJSONForParameters unmarshals JSON data into the given dest interface. dest must be a pointer to a struct, and any struct fields with the "parameters" tag must be of the Parameters type.
This method exists to enable unmarshaling of the same level of a JSON document to a struct and also to Parameters fields of the same struct.
Types ¶
type Explicit ¶
type Explicit[T Storable] struct { // contains filtered or unexported fields }
Explicit is permits storing a value such that it can be explicitly empty/zero.
Example (Bool) ¶
package main import ( "fmt" "github.com/splunk/go-splunk-client/pkg/attributes" "github.com/splunk/go-splunk-client/pkg/values" ) func main() { type knowledgeObject struct { Name string `values:"name"` Disabled attributes.Explicit[bool] `values:"disabled,omitzero"` } myObject := knowledgeObject{ Name: "my_knowledge_object", } // myObjectURLValues will not have a value for Disabled as it has not been set myObjectURLValues, _ := values.Encode(myObject) fmt.Printf("myObjectURLValues without explicitly set Disabled: %s\n", myObjectURLValues) myObject.Disabled = attributes.NewExplicit(false) // myObjectURLValues will have a value of false for Disabled as it has been set myObjectURLValues, _ = values.Encode(myObject) fmt.Printf("myObjectURLValues with explicitly set Disabled: %s\n", myObjectURLValues) }
Output: myObjectURLValues without explicitly set Disabled: map[name:[my_knowledge_object]] myObjectURLValues with explicitly set Disabled: map[disabled:[false] name:[my_knowledge_object]]
func NewExplicit ¶
NewExplicit returns a new Explicit with its value explicitly set.
func (Explicit[T]) Bool ¶
Bool returns a value indicating the boolean representation of the stored value, and another boolean that will be true only if the value was explicitly set, and it can be parsed by strconv.ParseBool without error.
func (Explicit[T]) GetURLValue ¶
func (e Explicit[T]) GetURLValue() interface{}
GetURLValue implements custom encoding of its url.Values value.
func (*Explicit[T]) UnmarshalJSON ¶
UnmarshalJSON implements custom JSON unmarshaling. The unmarshaled is explicitly set.
type NamedParameters ¶
type NamedParameters struct { // Name is the overall name of this set of Parameters. It is likely the leftmost segment // of a dotted parameter name, such as "actions" for "actions.email". Name string `values:"-"` // Status is the string representation of a NamedParameters' status. This is typically // true/false or 0/1, and is the value associated directly with the name segment, such as // email=true. Status Explicit[string] `values:",omitzero,anonymize"` Parameters Parameters `values:",omitzero,anonymize"` }
NamedParameters represent a set of Parameters that are associated with an overall Name.
type NamedParametersCollection ¶
type NamedParametersCollection []NamedParameters
NamedParametersCollection is a collection of NamedParameters.
func (NamedParametersCollection) EnabledNames ¶
func (collection NamedParametersCollection) EnabledNames() []string
EnabledNames returns a list of Names of the member NamedParameters that have a true Status value.
type Parameters ¶
Parameters is a map of parameter names to string values.
func (Parameters) SetURLValues ¶
func (p Parameters) SetURLValues(key string, v *url.Values) error
SetURLValues implements custom encoding into url.Values.
func (*Parameters) UnmarshalJSON ¶
func (p *Parameters) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom JSON unmarshaling which assumes the content being unmarshaled is a simple map of strings to a single value (string, bool, float, int). It returns an error if a value other than these types is encountered.