1.命令行输入以下命令来安装相关依赖包:
- go get github.com/dimiro1/banner
- go get github.com/mattn/go-colorable
package main import ( "fmt" "github.com/dimiro1/banner" "github.com/mattn/go-colorable" ) func init() { isEnabled := true isColorEnabled := true templ := `{{ .Title "Banner" "" 4 }} {{ .AnsiColor.BrightCyan }}The title will be ascii and indented 4 spaces{{ .AnsiColor.Default }} GoVersion: {{ .GoVersion }} GOOS: {{ .GOOS }} GOARCH: {{ .GOARCH }} NumCPU: {{ .NumCPU }} GOPATH: {{ .GOPATH }} GOROOT: {{ .GOROOT }} Compiler: {{ .Compiler }} ENV: {{ .Env "GOPATH" }} Now: {{ .Now "Monday, 2 Jan 2006" }} {{ .AnsiColor.BrightGreen }}This text will appear in Green {{ .AnsiColor.BrightRed }}This text will appear in Red{{ .AnsiColor.Default }}` banner.InitString(colorable.NewColorableStdout(), isEnabled, isColorEnabled, templ) fmt.Println("\nGo应用添加带彩色的启动横幅") } func main() { fmt.Println("Hi World!") }
标签:Lang,GOPATH,github,fmt,go,AnsiColor,Go,横幅,com From: https://www.cnblogs.com/codtina/p/18340831