fill

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 2, 2025 License: MIT Imports: 4 Imported by: 0

README

lesiw.io/fill

Go Reference

A utility for filling Go values.

Example

package main

import (
    "crypto/tls"
    "math/rand/v2"
    "testing"

    "github.com/google/go-cmp/cmp"
    "github.com/google/go-cmp/cmp/cmpopts"
    "lesiw.io/fill"
)

func TestTlsConfigClone(t *testing.T) {
    opts := cmp.Options{cmpopts.IgnoreUnexported(tls.Config{})}
    for range 100 {
        cfg := new(tls.Config)
        fill.Rand(cfg)
        if want, got := cfg, cfg.Clone(); !cmp.Equal(want, got, opts) {
            t.Errorf("-original +cloned\n%s", cmp.Diff(want, got, opts))
        }
    }
}

▶️ Run this example on the Go Playground

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Base64 = []rune{
	'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O',
	'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
	'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's',
	't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
	'8', '9', '+', '/',
}

Functions

func Rand added in v0.2.0

func Rand(a any)

Rand fills a value with random data.

func Zero added in v0.6.0

func Zero(a any)

Zero fills a value with zero-valued data.

Types

type Filler added in v0.6.0

type Filler struct {
	MinSize    int        // Arbitrary lower bound for value sizes.
	MaxSize    int        // Arbitrary upper bound for value sizes.
	Runes      []rune     // Runes to select from when filling strings.
	NeverNil   bool       // Never select nil for fillable values.
	RandSource *rand.Rand // Custom rand source.
}

A Filler fills in random values.

func (*Filler) Fill added in v0.6.0

func (f *Filler) Fill(a any)

Jump to

Keyboard shortcuts

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