stringer

package
v0.0.10 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stringify

func Stringify(v interface{}) string

Stringify converts a given interface into a human readable string

Example
package main

import (
	"fmt"

	"github.com/VirtusLab/kubedrainer/internal/stringer"
)

func main() {
	var value = []string{
		"one", "two", "three",
	}
	valuePtr := &value
	//lint:ignore S1021 needed for the test
	var valueInter interface{}
	valueInter = value
	valueInterPtr := &valueInter
	fmt.Println(stringer.Stringify(nil))
	fmt.Println(stringer.Stringify(""))
	fmt.Println(stringer.Stringify(value))
	fmt.Println(stringer.Stringify(valuePtr))
	fmt.Println(stringer.Stringify(&valuePtr))
	fmt.Println(stringer.Stringify(valueInter))
	fmt.Println(stringer.Stringify(valueInterPtr))
	fmt.Println(stringer.Stringify(&valueInterPtr))

}
Output:

<nil>

[one two three]
[one two three]
[one two three]
[one two three]
[one two three]
[one two three]
Example (Nested)
package main

import (
	"fmt"

	"github.com/VirtusLab/kubedrainer/internal/stringer"
)

type tester struct {
	one    string
	two    *string
	nested *tester
}

func main() {
	second := "second"
	t := &tester{
		one: "first",
		two: &second,
		nested: &tester{
			one:    "",
			two:    &second,
			nested: nil,
		},
	}

	fmt.Println(stringer.Stringify(t))

}
Output:

{one:first two:second nested:{one: two:second nested:<nil>}}

Types

This section is empty.

Jump to

Keyboard shortcuts

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