2 Star 1 Fork 1

mosache/YFrame

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
console.go 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
ヤ沒脩袮兲︶ 提交于 2021-08-27 18:12 . add module create command
package console
import (
"fmt"
"os"
"github.com/logrusorgru/aurora"
)
type (
Console interface {
Success(format string, a ...interface{})
Info(format string, a ...interface{})
Debug(format string, a ...interface{})
Warning(format string, a ...interface{})
Error(format string, a ...interface{})
Fatalln(format string, a ...interface{})
MarkDone()
Must(err error)
}
colorConsole struct {
}
// for idea log
ideaConsole struct {
}
)
func NewConsole(idea bool) Console {
if idea {
return NewIdeaConsole()
}
return NewColorConsole()
}
func NewColorConsole() *colorConsole {
return &colorConsole{}
}
func (c *colorConsole) Info(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println(msg)
}
func (c *colorConsole) Debug(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println(aurora.Blue(msg))
}
func (c *colorConsole) Success(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println(aurora.Green(msg))
}
func (c *colorConsole) Warning(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println(aurora.Yellow(msg))
}
func (c *colorConsole) Error(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println(aurora.Red(msg))
}
func (c *colorConsole) Fatalln(format string, a ...interface{}) {
c.Error(format, a...)
os.Exit(1)
}
func (c *colorConsole) MarkDone() {
c.Success("Done.")
}
func (c *colorConsole) Must(err error) {
if err != nil {
c.Fatalln("%+v", err)
}
}
func NewIdeaConsole() *ideaConsole {
return &ideaConsole{}
}
func (i *ideaConsole) Info(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println(msg)
}
func (i *ideaConsole) Debug(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println(aurora.Blue(msg))
}
func (i *ideaConsole) Success(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println("[SUCCESS]: ", msg)
}
func (i *ideaConsole) Warning(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println("[WARNING]: ", msg)
}
func (i *ideaConsole) Error(format string, a ...interface{}) {
msg := fmt.Sprintf(format, a...)
fmt.Println("[ERROR]: ", msg)
}
func (i *ideaConsole) Fatalln(format string, a ...interface{}) {
i.Error(format, a...)
os.Exit(1)
}
func (i *ideaConsole) MarkDone() {
i.Success("Done.")
}
func (i *ideaConsole) Must(err error) {
if err != nil {
i.Fatalln("%+v", err)
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mosache/YFrame.git
git@gitee.com:mosache/YFrame.git
mosache
YFrame
YFrame
v0.1.36

搜索帮助

0d507c66 1850385 C8b1a773 1850385