app/history/helper.go

68 lines
1.1 KiB
Go
Raw Normal View History

2021-12-16 13:43:56 +00:00
package history
2021-12-18 09:30:05 +00:00
import (
"fmt"
"kumoly.io/kumoly/app/util"
)
2021-12-16 13:43:56 +00:00
func Error() *History {
h := getBase()
h.Type = ERROR
2021-12-19 10:52:40 +00:00
if !util.PROD {
2021-12-16 13:43:56 +00:00
h.Trace = util.Stack()
}
return h
}
func Info() *History {
h := getBase()
h.Type = INFO
return h
}
func getBase() *History {
mod, file := util.CallerMod(3)
h := &History{
Module: mod,
Caller: file,
}
return h
}
2021-12-16 15:58:02 +00:00
2021-12-16 18:03:07 +00:00
func (h *History) Nm(name string) *History {
h.Name = name
return h
}
2021-12-16 15:58:02 +00:00
func (h *History) Msg(msg string) *History {
h.Message = msg
return h
}
2021-12-18 09:30:05 +00:00
func (h *History) Msgf(msg string, args ...interface{}) *History {
h.Message = fmt.Sprintf(msg, args...)
return h
}
2021-12-16 15:58:02 +00:00
func (h *History) Bd(body interface{}) *History {
h.Body = body
return h
}
func (h *History) Iss(issuer string) *History {
h.Issuer = issuer
return h
}
2021-12-16 15:59:16 +00:00
func (h *History) Grp(grp string) *History {
h.Group = grp
return h
}
2021-12-17 09:03:56 +00:00
func (h *History) Scp(scp string) *History {
h.Scope = scp
return h
}
// Mod alter the derived module name, and put the original mod to scope
func (h *History) Mod(mod string) *History {
h.Scope = h.Module
h.Module = mod
2021-12-17 07:52:32 +00:00
return h
}