util

package
v0.0.0-...-586e974 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2019 License: BSD-2-Clause Imports: 8 Imported by: 0

Documentation

Overview

Contains various utility functions.

Index

Constants

This section is empty.

Variables

View Source
var Prof = Profiler{/* contains filtered or unexported fields */}

Functions

func Diff

func Diff(a, b string) string

func Exists

func Exists(strs []string, s string) bool

Checks if element exists in a slice of strings

func PascalCaseToSnakeCase

func PascalCaseToSnakeCase(in string) string

func Remove

func Remove(strs []string, s string) []string

Removes an element from slice of strings

Types

type HasID

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

HasID is an utility struct typically embedded to give the type a unique id

func (*HasID) ID

func (i *HasID) ID() ID

ID return the id from type HasID

type HasSettings

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

HasSettings is an utility struct that is typically embedded in other type structs to make that type implement the SettingsInterface

func (*HasSettings) Settings

func (s *HasSettings) Settings() *Settings

Settings get the settings from HasSettings type

type ID

type ID uint32

ID is a unique uint32 value

type IDInterface

type IDInterface interface {
	ID() ID
}

IDInterface has an ID method

type OnChangeCallback

type OnChangeCallback func(name string)

OnChangeCallback is a func with a parameter name

type Op

type Op int

A comparison operation used in context queries.

const (
	OpEqual            Op = iota //< Compare for equality.
	OpNotEqual                   //< Compare for difference.
	OpRegexMatch                 //< Compare for a regular expression match.
	OpNotRegexMatch              //< Compare for a regular expression difference.
	OpRegexContains              //< Compare whether the given regular expression matches some substring of the operand.
	OpNotRegexContains           //< Compare whether the given regular expression does not match some substring of the operand.
)

func (*Op) UnmarshalJSON

func (o *Op) UnmarshalJSON(d []byte) error

type ProfToken

type ProfToken struct {
	Name string
	// contains filtered or unexported fields
}

func (*ProfToken) Exit

func (pt *ProfToken) Exit()

type ProfileEntry

type ProfileEntry struct {
	Calls   int
	Tottime time.Duration
}

type ProfileResult

type ProfileResult struct {
	Name string
	ProfileEntry
}

func (*ProfileResult) Avg

func (v *ProfileResult) Avg() time.Duration

func (ProfileResult) String

func (v ProfileResult) String() string

type Profiler

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

func (*Profiler) Enter

func (p *Profiler) Enter(name string) ProfToken

func (*Profiler) Results

func (p *Profiler) Results() (ret []ProfileResult)

func (*Profiler) SortByAvgTime

func (p *Profiler) SortByAvgTime() []ProfileResult

func (*Profiler) SortByName

func (p *Profiler) SortByName() []ProfileResult

func (*Profiler) SortByTotalTime

func (p *Profiler) SortByTotalTime() []ProfileResult

func (*Profiler) String

func (p *Profiler) String() (ret string)

type Settings

type Settings struct {
	HasID
	// contains filtered or unexported fields
}

Settings is a struct of settings

func NewSettings

func NewSettings() Settings

NewSettings create a new Settings

func (*Settings) AddOnChange

func (s *Settings) AddOnChange(key string, cb OnChangeCallback)

AddOnChange adds a OnChangeCallback identified with the given key. If a callback is already defined for that name, it is overwritten

func (*Settings) Bool

func (s *Settings) Bool(name string, def ...interface{}) bool

Bool convert the setting identified with the given name to bool.

func (*Settings) ClearOnChange

func (s *Settings) ClearOnChange(key string)

ClearOnChange removes the OnChangeCallback associated with the given key.

func (*Settings) Erase

func (s *Settings) Erase(name string)

Erase erases the setting associated with the given key from this settings object

func (*Settings) Get

func (s *Settings) Get(name string, def ...interface{}) interface{}

Get the setting identified with the given name. An optional default value may be specified. If the setting does not exist in this object, the parent if available will be queried.

func (*Settings) Has

func (s *Settings) Has(name string) bool

Has returns whether the setting identified by this key exists in this settings object

func (*Settings) Int

func (s *Settings) Int(name string, def ...interface{}) int

Int convert the setting identified with the given name to int.

func (*Settings) MarshalJSON

func (s *Settings) MarshalJSON() (data []byte, err error)

MarshalJSON settings to data

func (*Settings) Parent

func (s *Settings) Parent() SettingsInterface

Parent returns the parent Settings of this Settings object

func (*Settings) Set

func (s *Settings) Set(name string, val interface{})

Set sets the setting identified with the given key to the specified value

func (*Settings) SetParent

func (s *Settings) SetParent(p SettingsInterface)

SetParent sets the parent Settings of this Settings object

func (*Settings) String

func (s *Settings) String(name string, def ...interface{}) string

String convert the setting identified with the given name to string.

func (*Settings) UnmarshalJSON

func (s *Settings) UnmarshalJSON(data []byte) error

UnmarshalJSON from data to Settings

type SettingsInterface

type SettingsInterface interface {
	Settings() *Settings
}

SettingsInterface defines an interface for types that have settings

Jump to

Keyboard shortcuts

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