sugar

package module
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

README

sugar

GoDoc

Syntactic Sugar for Golang

This package provides some convenience functions that help keep code clean.

Documentation

Overview

Package sugar provides convenience functions for keeping code clean and less repetitive.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorWriter      = os.Stderr
	ErrorPrefix      = "Error:"
	ErrorFmt         = "%s %+v"
	StandardExitCode = 1

	PanicFunc = func(err error) {
		panic(err)
	}
	ErrorPrintFunc = func(err error) {
		fmt.Fprintf(ErrorWriter, ErrorFmt, ErrorPrefix, err)
	}
	ExitFunc = func(code int) {
		os.Exit(code)
	}
)

Functions

func BoolPtr

func BoolPtr(v bool) *bool

BoolPtr takes a bool literal and returns a pointer.

func BytePtr

func BytePtr(v byte) *byte

BytePtr takes a byte literal and returns a pointer.

func Check

func Check(err error)

Check takes an error and prints it if it is not nil; but will continue.

func CheckExit

func CheckExit(err error, code ...int)

CheckExit takes an error and will print it and exit if it is not nil. If no exit code is provided, the StandardExitCode will be used. Any exit codes beyond the first one one provided will be discarded.

func CheckPanic

func CheckPanic(err error)

CheckPanic takes an error and will panic if it is not nil.

func Complex64Ptr

func Complex64Ptr(v complex64) *complex64

Complex64Ptr takes a complex64 literal and returns a pointer.

func Complex128Ptr

func Complex128Ptr(v complex128) *complex128

Complex128Ptr takes a complex128 literal and returns a pointer.

func Float32Ptr

func Float32Ptr(v float32) *float32

Float32Ptr takes float32 literal and returns a pointer.

func Float64Ptr

func Float64Ptr(v float64) *float64

Float64Ptr takes a float64 literal and returns a pointer.

func Int8Ptr

func Int8Ptr(v int8) *int8

Int8Ptr takes an int8 literal and returns a pointer.

func Int16Ptr

func Int16Ptr(v int16) *int16

Int16Ptr takes an int16 literal and returns a pointer.

func Int32Ptr

func Int32Ptr(v int32) *int32

Int32Ptr takes an int32 literal and returns a pointer.

func Int64Ptr

func Int64Ptr(v int64) *int64

Int64Ptr takes an int64 literal and returns a pointer.

func IntPtr

func IntPtr(v int) *int

IntPtr takes an int literal and returns a pointer.

func RunePtr

func RunePtr(v rune) *rune

RunePtr takes a rune literal and returns a pointer.

func StrPtr

func StrPtr(v string) *string

StrPtr is an alias of StringPtr.

func StringPtr

func StringPtr(v string) *string

StringPtr takes a string literal and returns a pointer.

func Uint8Ptr

func Uint8Ptr(v uint8) *uint8

Uint8 takes a uint8 literal and returns a pointer.

func Uint16Ptr

func Uint16Ptr(v uint16) *uint16

Uint16Ptr takes a uint16 literal and returns a pointer.

func Uint32Ptr

func Uint32Ptr(v uint32) *uint32

Uint32Ptr takes uint32 literal and returns a pointer.

func Uint64Ptr

func Uint64Ptr(v uint64) *uint64

Uint64Ptr takes uint64 literal and returns a pointer.

func UintPtr

func UintPtr(v uint) *uint

UintPtr takes a uint literal and returns a pointer.

Types

type StrSet

type StrSet map[string]struct{}

StrSet a set type for strings.

func (*StrSet) Add

func (s *StrSet) Add(str string)

Add adds a new key to the set if it does not already exist.

func (*StrSet) AddHas

func (s *StrSet) AddHas(str string) bool

AddHas behaves like Add, but returns true if the key already existed.

func (*StrSet) Has

func (s *StrSet) Has(str string) bool

Has checks if the given string is present in the set.

Jump to

Keyboard shortcuts

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