-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgoext.go
39 lines (33 loc) · 875 Bytes
/
goext.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Package goext adds various extensions for the go language.
package goext
import (
"fmt"
)
// Ternary adds the missing ternary operator.
func Ternary[T any](cond bool, vtrue, vfalse T) T {
if cond {
return vtrue
}
return vfalse
}
// Printfln allows using Printf and Println in one call.
func Printfln(format string, a ...any) (n int, err error) {
text := fmt.Sprintf(format, a...)
return fmt.Println(text)
}
// PanicOnError panics if the given error is set.
func PanicOnError(err error) {
if err != nil {
panic(err)
}
}
// Noop is a no operation function that can be used for tasks.
// For example if they are just used for multiple dependencies.
func Noop() error {
return nil
}
// Pass is a no-op function that can be used to set variables to used.
// Useful during development but must be removed afterwards!
func Pass(i ...interface{}) {
// No-Op
}