helpers

package
v0.4.118 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Overview

Borrowed from https://www.calhoun.io/creating-random-strings-in-go/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clone added in v0.0.508

func Clone[T any](v T) T

Clone clones *public fields* in a structure. Private fields may or may not be copied, and private pointers may or may not point into the original object.

  • this will panic if the structure is not serializable
  • See CloneFallible

func CloneFallible added in v0.0.508

func CloneFallible[T any](v T) (T, error)

CloneFallible clones *public fields* in a structure. Private fields may or may not be copied, and private pointers may or may not point into the original object.

  • returns an error if the structure is not serializable
  • See Clone

func DirectoryExists

func DirectoryExists(path string) bool

func Duration

func Duration(d time.Duration, dicimal int) time.Duration

func FileExists

func FileExists(path string) bool

func GetConfigDirectory added in v0.1.123

func GetConfigDirectory() (string, error)

GetConfigDirectory will return where config and state files should be stored, either respecting `FLY_CONFIG_DIR` or defaulting to the user's home directory at `~/.fly`.

func HasPipedStdin

func HasPipedStdin() bool

HasPipedStdin returns if stdin has piped input

func IsTerminal added in v0.0.183

func IsTerminal() bool

func MakeSimpleTable added in v0.0.145

func MakeSimpleTable(out io.Writer, headings []string) (table *tablewriter.Table)

func MkdirAll

func MkdirAll(pathname string) error

func ParseSize added in v0.1.88

func ParseSize(s string, parser func(string) (int64, error), quotient int) (int, error)

func PathRelativeToCWD

func PathRelativeToCWD(path string) string

func RandBytes added in v0.0.348

func RandBytes(n int) ([]byte, error)

RandBytes generates random bytes of a given length See: https://stackoverflow.com/questions/35781197/generating-a-random-fixed-length-byte-array-in-go

func RandHex added in v0.3.8

func RandHex(n int) (string, error)

RandHex generates a random hex string of a given length*2

func RandString added in v0.0.261

func RandString(n int) (string, error)

RandString returns a string of n bytes, consisting of ASCII letters or numbers.

func ReadStdin

func ReadStdin(maxLength int) (string, error)

func WriteFileAtomically added in v0.4.112

func WriteFileAtomically(path string, data []byte, perm os.FileMode) (err error)

WriteFileAtomically writes data to a temporary file beside path, flushes it to disk, and renames it over path. A write that fails part way, for example on a full disk, leaves whatever was at path untouched. The rename also means a reader that already had the old file open never sees the new contents, so a file carrying a credential can safely be rewritten over a more permissive one. os.WriteFile truncates first and writes second, which both leaves an empty file behind on failure (an empty config reads back as a logged-out flyctl) and exposes the new contents through any open handle at the old mode.

Types

This section is empty.

Jump to

Keyboard shortcuts

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