funcs

package
v0.19.4 Latest Latest
Warning

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

Go to latest
Published: May 8, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetPath

func GetPath(v *viper.Viper) func(key string) []string

GetPath returns a GetFunc that expands a slice of strings into individual paths based on standard POSIX shell $PATH separator parsing.

Example
package main

import (
	"fmt"

	"github.com/spf13/viper"

	"vitess.io/vitess/go/viperutil"
	"vitess.io/vitess/go/viperutil/funcs"
	"vitess.io/vitess/go/viperutil/internal/value"
)

func main() {
	v := viper.New()

	val := viperutil.Configure("path", viperutil.Options[[]string]{
		GetFunc: funcs.GetPath,
	})

	stub(val, v)

	v.Set(val.Key(), []string{"/var/www", "/usr:/usr/bin", "/vt"})
	fmt.Println(val.Get())
}

func stub[T any](val viperutil.Value[T], v *viper.Viper) {
	// N.B.: You cannot do this in normal code because these types are internal
	// to viperutil, but you also will not need to do this. However it's
	// necessary for the example to work here.
	base := val.(*value.Static[T]).Base
	base.BoundGetFunc = base.GetFunc(v)
}
Output:

[/var/www /usr /usr/bin /vt]

Types

This section is empty.

Jump to

Keyboard shortcuts

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