deepset

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2022 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package deepset provides functionality to set a value of a given type on a value of any time that is or contains a value of the same type.

Package deepset provides functionality to set the an input object's value directly, or set it on one of the object's struct fields, based on the type of the value being set.

Example (Set)
package main

import (
	"fmt"

	"github.com/splunk/go-splunk-client/pkg/deepset"
)

type Namespace struct {
	User string
	App  string
}

type ID struct {
	Title     string
	Namespace Namespace
}

type View struct {
	ID      ID
	Content string
}

func main() {
	myView := View{}

	// returned error ignored here
	_ = deepset.Set(&myView, Namespace{User: "admin", App: "search"})

	fmt.Printf("ID User: %s, App: %s", myView.ID.Namespace.User, myView.ID.Namespace.App)
}
Output:

ID User: admin, App: search

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Set

func Set(dest interface{}, value interface{}) error

Set attempts to set the given value on dest.

If dest and value are of the same underlying type, dest will be set directly.

If dest is a struct, and exactly one of its fields are of the same underlying type as value, that field will be set to value.

Any dest field that is a struct will be followed recursively.

If multiple struct fields at any given level match the value type, an error is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

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