util

package
v8.5.0 Latest Latest
Warning

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

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

Documentation

Overview

Package util provides general helpers used by Relay code.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorJSONMsg

func ErrorJSONMsg(msg string) (j []byte)

ErrorJSONMsg returns a json-encoded error message

func ErrorJSONMsgf

func ErrorJSONMsgf(fmtStr string, args ...interface{}) []byte

ErrorJSONMsgf returns a json-encoded error message using the printf formatter

func RedactURL

func RedactURL(inputURL string) string

RedactURL is equivalent to parsing a URL string and then calling Redacted() to replace passwords, if any, with xxxxx. We still support Go 1.14 so we can't use the actual URL.Redacted().

Types

type CleanupTasks

type CleanupTasks []func()

CleanupTasks accumulates a list of things which should be done at the end of a method unless Clear() is called. Intended usage:

var cleanup CleanupTasks
defer cleanup.Run()

thing1 := createThing1()
cleanup.AddCloser(thing1)

err := doSomethingElse()
if err != nil {
	return err // thing1 will be disposed of automatically
}

cleanup.Clear() // everything succeeded so we don't want thing1 to be disposed of

func (*CleanupTasks) AddCloser

func (t *CleanupTasks) AddCloser(c io.Closer)

AddCloser adds a task for calling Close on an object

func (*CleanupTasks) AddFunc

func (t *CleanupTasks) AddFunc(f func())

AddFunc adds a task.

func (*CleanupTasks) Clear

func (t *CleanupTasks) Clear()

Clear clears all tasks that were added.

func (*CleanupTasks) Run

func (t *CleanupTasks) Run()

Run runs all of the tasks.

type StringMemoizer

type StringMemoizer struct {
	// contains filtered or unexported fields
}

StringMemoizer is a simple encapsulation of a lazily evaluated-only-once string function.

func NewStringMemoizer

func NewStringMemoizer(computeFn func() string) *StringMemoizer

NewStringMemoizer creates a new uninitialized StringMemoizer.

func (*StringMemoizer) Get

func (m *StringMemoizer) Get() string

Get returns the result of the computeFn, calling it only if it has not already been called.

Jump to

Keyboard shortcuts

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