Documentation
¶
Overview ¶
Package must is a syntax sugar package to make the use of `Must` functions.
The `must` package provides an easy way to make functions panic on error. This is typically used at the global variable scope where returning an error is inconvenient and meaningful error recovery isn't possible due to it being a programming error. For example, the two variant functions behave the same:
must.Must(regexp.Compile(`regexp`)) regexp.Must(regexp.Compile(`regexp`)
Dot import can be used since the package is intentionally kept small and focused on this specific topic:
Must(regexp.Compile(`regexp`))
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Must ¶
Must is a syntax sugar to express things like must.Must(regexp.Compile(`regexp`))
Example ¶
package main import ( "go.llib.dev/frameless/pkg/must" ) func main() { fn := func() (int, error) { return 42, nil } val := must.Must(fn()) _ = val }
Example (HtmlTemplate) ¶
package main import ( htmlTemplate "html/template" "go.llib.dev/frameless/pkg/must" ) func main() { tmpl := must.Must(htmlTemplate.New("").Parse(`<div>{{.Label}}</div>`)) _ = tmpl }
Example (IoReadAll) ¶
package main import ( "bytes" "io" "go.llib.dev/frameless/pkg/must" ) func main() { in := bytes.NewReader([]byte("Hello, world!")) data := must.Must(io.ReadAll(in)) _ = data }
Example (Regexp) ¶
package main import ( "regexp" "go.llib.dev/frameless/pkg/must" ) func main() { must.Must(regexp.Compile(`^\w+$`)) }
Example (TextTemplate) ¶
package main import ( txtTemplate "text/template" "go.llib.dev/frameless/pkg/must" ) func main() { tmpl := must.Must(txtTemplate.New("").Parse(`{{.Label}}`)) _ = tmpl }
func Must2 ¶
Example ¶
package main import ( "go.llib.dev/frameless/pkg/must" ) func main() { fn := func() (string, int, error) { return "the answer is", 42, nil } a, b := must.Must2(fn()) _, _ = a, b }
func Must3 ¶
Example ¶
package main import ( "go.llib.dev/frameless/pkg/must" ) func main() { fn := func() (string, int, bool, error) { return "the answer is", 42, true, nil } a, b, c := must.Must3(fn()) _, _, _ = a, b, c }
func Must4 ¶
Example ¶
package main import ( "go.llib.dev/frameless/pkg/must" ) func main() { fn := func() (string, int, bool, float32, error) { return "the answer is", 42, true, 42.42, nil } a, b, c, d := must.Must4(fn()) _, _, _, _ = a, b, c, d }
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.