gg

package module
v0.0.0-...-8d17c81 Latest Latest
Warning

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

Go to latest
Published: Jan 26, 2024 License: MIT Imports: 0 Imported by: 12

README

gg

Useful golang utilities.

Documentation

Overview

Package gg is a set of useful golang utilities.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func If

func If[T any](cond bool, truePart T, falsePart T) T

If returns truePart if cond is true, or returns falsePart. Something like ternary operator in C:

cond ? truePart : falsePart

func IfFunc

func IfFunc[T any](cond bool, truePart func() T, falsePart func() T) T

IfFunc calls truePart() and returns it's return value if cond is true, or calls falsePart() and returns it's return value. If cond is true, falsePart will not be executed. if cond if false, truePart will not be executed. Something like ternary operator in C:

cond ? truePart() : falsePart()

func Must

func Must[T any](v T, err error) T

Must returns v if err is nil, or it panic with err. Must is useful to wrap a function call returning value and error when there is no better way to handle the error other than panicking.

Example
package main

import (
	"fmt"
	"strconv"

	"github.com/mkch/gg"
)

func main() {
	fmt.Print(gg.Must(strconv.Atoi("1")))
}
Output:

1

func MustOK

func MustOK(err error)

MustOK panics if err is not nil.

Example
package main

import (
	"os"

	"github.com/mkch/gg"
)

func main() {
	gg.MustOK(os.Setenv("some_key_for_test", "some value"))
}
Output:

Types

This section is empty.

Directories

Path Synopsis
Package filepath implements utility routines for manipulating filename paths.
Package filepath implements utility routines for manipulating filename paths.

Jump to

Keyboard shortcuts

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