1234567891011121314151617181920212223242526272829303132333435363738394041 |
- package goreport
- import (
- "fmt"
- "os"
- )
- // Code execution state.
- type Report struct {
- // Exit status.
- Code int
- // Status message.
- Err string
- // Evaluation and modification of data.
- EvalFunc func(r Report) Report
- // Saved call frames.
- frames []frame
- // User data.
- Tags map[string]any
- }
- // Evaluate r and return the result.
- func (r Report) Eval() Report {
- return r.EvalFunc(r)
- }
- // Exit the program with the r.Code.
- func (r Report) Exit() {
- os.Exit(r.Code)
- }
- // Return Report with the value of err in Err.
- func New[T ~string](err T) Report {
- return Report{Err: string(err)}
- }
- // Return Report with the formatted specifier in Err.
- func Newf(format string, errs ...any) Report {
- return Report{Err: fmt.Sprintf(format, errs...)}
- }
|