代码拉取完成,页面将自动刷新
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)
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。