An easy way to add useful startup banners into your Go applications

Build Status Go Report Card GoDoc

Try browsing the code on Sourcegraph!

Banner

Add beautiful banners into your Go applications

Table of Contents

Motivation

I Like to add these startup banners on all my applications, I think it give personality to the application.

Usage

Import the package. Thats it.

package main

import _ "github.com/dimiro1/banner/autoload"

func main() {}

By default it look at the file banner.txt in the same directory. You can customize with the command line flags.

If you do not want to use the autoload package you can always fallback to the banner API

package main

import (
	"bytes"
	"os"

	"github.com/dimiro1/banner"
)

func main() {
  isEnabled := true
  isColorEnabled := true
  banner.Init(os.Stdout, isEnabled, isColorEnabled, bytes.NewBufferString("My Custom Banner"))
}

If using windows, use go-colorable. This works in all-platforms.

package main

import (
	"bytes"
	"os"

	"github.com/dimiro1/banner"
	"github.com/mattn/go-colorable"
)

func main() {
  isEnabled := true
  isColorEnabled := true
  banner.Init(colorable.NewColorableStdout(), isEnabled, isColorEnabled, bytes.NewBufferString("My Custom Banner"))
}

API

I recommend you to vendor this dependency in your project, as it is a good practice.

Command line flags

$ go run main.go -h

should output

Usage of main:
  -ansi
    	ansi colors enabled? (default true)
  -banner string
    	banner.txt file (default "banner.txt")
  -show-banner
    	print the banner? (default true)

Template

You can use the following variables in the template.

Variable Value
{{ .Title "YourTitle" "fontname" indent }} <Generated ASCII art>
{{ .GoVersion }} runtime.Version()
{{ .GOOS }} runtime.GOOS
{{ .GOARCH }} runtime.GOARCH
{{ .NumCPU }} runtime.NumCPU()
{{ .GOPATH }} os.Getenv("GOPATH")
{{ .GOROOT }} runtime.GOROOT()
{{ .Compiler }} runtime.Compiler
{{ .Env "GOPATH" }} os.Getenv("GOPATH")
{{ .Now "Monday, 2 Jan 2006" }} time.Now().Format("Monday, 2 Jan 2006")

Please see the layout of the function .Now in https://github.com/golang/go/blob/f06795d9b742cf3292a0f254646c23603fc6419b/src/time/format.go#L9-L41

Title

Title generates ascii art for you using go-figure Use it if you don't provide your own ascii title.

See examples/title for an example

Note: Must provide zero values if not using something i.e.

// .Title string   string    int
// .Title title    fontname  indentation_spaces
{{ .Title "Banner" ""        0 }}
{{ .Title "Banner" "banner2" 0 }}
{{ .Title "Banner" ""        4 }}

The fonts available can be seen here go-figure#supported-fonts

Colors

There are support for ANSI colors :)

Variable
{{ .AnsiColor.Default }}
{{ .AnsiColor.Black }}
{{ .AnsiColor.Red }}
{{ .AnsiColor.Green }}
{{ .AnsiColor.Yellow }}
{{ .AnsiColor.Blue }}
{{ .AnsiColor.Magenta }}
{{ .AnsiColor.Cyan }}
{{ .AnsiColor.White }}
{{ .AnsiColor.BrightBlack }}
{{ .AnsiColor.BrightRed }}
{{ .AnsiColor.BrightGreen }}
{{ .AnsiColor.BrightYellow }}
{{ .AnsiColor.BrightBlue }}
{{ .AnsiColor.BrightMagenta }}
{{ .AnsiColor.BrightCyan }}
{{ .AnsiColor.BrightWhite }}
{{ .AnsiBackground.Default }}
{{ .AnsiBackground.Black }}
{{ .AnsiBackground.Red }}
{{ .AnsiBackground.Green }}
{{ .AnsiBackground.Yellow }}
{{ .AnsiBackground.Blue }}
{{ .AnsiBackground.Magenta }}
{{ .AnsiBackground.Cyan }}
{{ .AnsiBackground.White }}
{{ .AnsiBackground.BrightBlack }}
{{ .AnsiBackground.BrightRed }}
{{ .AnsiBackground.BrightGreen }}
{{ .AnsiBackground.BrightYellow }}
{{ .AnsiBackground.BrightBlue }}
{{ .AnsiBackground.BrightMagenta }}
{{ .AnsiBackground.BrightCyan }}
{{ .AnsiBackground.BrightWhite }}

Want to see a nyancat?

$ go run examples/file/main.go -banner examples/file/nyancat.txt

NyanCat Banner

Example

  ____
 |  _ \
 | |_) | __ _ _ __  _ __   ___ _ __
 |  _ < / _` | '_ \| '_ \ / _ \ '__|
 | |_) | (_| | | | | | | |  __/ |
 |____/ \__,_|_| |_|_| |_|\___|_|

GoVersion: {{ .GoVersion }}
GOOS: {{ .GOOS }}
GOARCH: {{ .GOARCH }}
NumCPU: {{ .NumCPU }}
GOPATH: {{ .GOPATH }}
GOROOT: {{ .GOROOT }}
Compiler: {{ .Compiler }}
ENV: {{ .Env "GOPATH" }}
Now: {{ .Now "Monday, 2 Jan 2006" }}

will output something like this

  ____
 |  _ \
 | |_) | __ _ _ __  _ __   ___ _ __
 |  _ < / _` | '_ \| '_ \ / _ \ '__|
 | |_) | (_| | | | | | | |  __/ |
 |____/ \__,_|_| |_|_| |_|\___|_|

GoVersion: go1.6
GOOS: darwin
GOARCH: amd64
NumCPU: 4
GOPATH: /Users/claudemiro/go
GOROOT: /usr/local/Cellar/go/1.6/libexec
Compiler: gc
ENV: /Users/claudemiro/go
Now: Friday, 26 Mar 2016

Log

I am using the standard golang log, but there is a function SetLog that accepts a custom log, so you can customize the way you want.

ASCII Banners

Access http://patorjk.com/software/taag/#p=display&f=Big&t=Banner to generate ASCII banners.

Or use {{ .Title }} template

LICENSE

The MIT License (MIT)

Copyright (c) 2016 Claudemiro

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Owner
Claudemiro
@golang, @python developer, but can work well with Java and @nodejs.
Claudemiro
Comments
  • using banner with new version of golang

    using banner with new version of golang

    Hi,

    Using banner in my project with golang 15 it works perfectly for app execution but fails when trying to write tests:

    "flag provided but not defined: -test.testlogfile"

    this is due to flag.Parse() in autoload.go.

    Is there some workaround to use the banner with newer versions of golang?

  • I can't find InitString()

    I can't find InitString()

    Hello, I want to use your lib to add banner to my program, but when I trying to run your title example, go can't find InitString method and GoLand shows only Init and SetLog methods. Also, if I try to replace InitString with Init and convert templ to bytes, like in your quickstart, it just don't show anything.

    Strange cause I downloaded your repo now and with your repo it works, maybe cause my go 1.15 version? I see 1.11 in your go.mod

  • not working on OSX ?

    not working on OSX ?

    i tried this, with a banner.txt file with ascii in it.

    
    package main
    
    import (
        "os"
        "bytes"
    
        "github.com/dimiro1/banner"
    )
    
    func main() {
    
        // set banner
        isEnabled := true
        isColorEnabled := false
        banner.Init(os.Stdout, isEnabled, isColorEnabled, bytes.NewBufferString("mainBanner.txt"))
    
    

    Dont see anything at all.

    Also is there a way to embedd the ASCII and load it ? A file with the ASCI in it, means one more thing to make sure is deployed. Not good.

  • banner is overriding other command line flags

    banner is overriding other command line flags

    Hello,

    My example application has couple of command line flags which i have parsed with pflag. But whenever i use github.com/dimiro1/banner/autoload it overrides my current flags and prints below when i run my binary with -h . I would expect instead of overriding my flags, appending to them actually.

    Below is my application's expected command line flags:

    $ ./main --help
    Usage of ./main:
          --createUserUrl string   url of the user creation on Oreilly API (default "https://learning.oreilly.com/api/v1/user/")
          --emailDomain string     usable domain for creating trial account, it should be a valid domain (default "jentrix.com")
          --length int             length of the random generated username and password (default 12)
    

    And this is the flags when i use banner, as you see, my application's flags are missing:

    $ ./main --help
    Usage of ./main:
      -ansi
            ansi colors enabled? (default true)
      -banner string
            banner.txt file (default "banner.txt")
      -show-banner
            print the banner? (default true)
    

    I would expect something like that:

    $ ./main --help
    Usage of ./main:
          --createUserUrl string   url of the user creation on Oreilly API (default "https://learning.oreilly.com/api/v1/user/")
          --emailDomain string     usable domain for creating trial account, it should be a valid domain (default "jentrix.com")
          --length int              length of the random generated username and password (default 12)
          -ansi                       ansi colors enabled? (default true)
          -banner string        banner.txt file (default "banner.txt")
          -show-banner        print the banner? (default true)
    

    Same situation repeats even if i use go's default flag package instead of pflag.

  • Add ascii title generation closes #4

    Add ascii title generation closes #4

    For #4

    • [x] Added Title template option
    • [x] Added example at examples/title
    • [x] Updated readme
    • [x] Moved existing example to examples/file and also updated readme
    • [x] Added test case
    • [ ] Add color support after PR https://github.com/common-nighthawk/go-figure/pull/16 lands
Related tags
Yubigo is a Yubikey client API library that provides an easy way to integrate the Yubico Yubikey into your existing Go-based user authentication infrastructure.

yubigo Yubigo is a Yubikey client API library that provides an easy way to integrate the Yubikey into any Go application. Installation Installation is

Oct 27, 2022
Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Hack this repo and add your name to the list above. Creativity and style encouraged in both endeavors.

Oct 1, 2021
Package fsm allows you to add finite-state machines to your Go code.

fsm Package fsm allows you to add finite-state machines to your Go code. States and Events are defined as int consts: const ( StateFoo fsm.State =

Dec 9, 2022
Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.
Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app.

Package buildinfo provides basic building blocks and instructions to easily add build and release information to your app. This is done by replacing variables in main during build with ldflags.

Nov 14, 2021
Gorsair hacks its way into remote docker containers that expose their APIs
Gorsair hacks its way into remote docker containers that expose their APIs

Gorsair Gorsair is a penetration testing tool for discovering and remotely accessing Docker APIs from vulnerable Docker containers. Once it has access

Dec 31, 2022
IBus Engine for GoVarnam. An easy way to type Indian languages on GNU/Linux systems.

IBus Engine For GoVarnam An easy way to type Indian languages on GNU/Linux systems. goibus - golang implementation of libibus Thanks to sarim and haun

Feb 10, 2022
An easy to use, extensible health check library for Go applications.

Try browsing the code on Sourcegraph! Go Health Check An easy to use, extensible health check library for Go applications. Table of Contents Example M

Dec 30, 2022
Create one endpoint with add user functionality

hubuc-task Create one endpoint with add user functionality

Nov 13, 2021
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way to say thanks to the maintainers of the modules you use and the contributors of Go itself.
GoThanks automatically stars Go's official repository and your go.mod github dependencies, providing a simple way  to say thanks to the maintainers of the modules you use and the contributors of Go itself.

Give thanks (in the form of a GitHub ★) to your fellow Go modules maintainers. About GoThanks performs the following operations Sends a star to Go's r

Dec 24, 2022
Orders - An example of gin contains many useful features
Orders - An example of gin contains many useful features

Go Gin Example An example of gin contains many useful features 简体中文 Installation

Feb 22, 2022
Enable your Golang applications to self update with S3

s3update Enable your Golang applications to self update with S3. Requires Go 1.8+ This package enables our internal tools to be updated when new commi

Jul 20, 2022
Host yo' self from your browser, your phone, your toaster.
Host yo' self from your browser, your phone, your toaster.

A hosting service from the browser, because why not. Try it at hostyoself.com. See it in action Here's an example where I use hostyoself.com to host i

Jan 1, 2023
Portapps is not affiliated, associated, authorized, endorsed by, or in any way officially connected with IntelliJ IDEA
Portapps is not affiliated, associated, authorized, endorsed by, or in any way officially connected with IntelliJ IDEA

Portapps is not affiliated, associated, authorized, endorsed by, or in any way officially connected with IntelliJ IDEA

Feb 27, 2022
Ghdl - A much more convenient way to download GitHub release binaries on the command line, works on Win & Unix-like systems

ghdl Memorize ghdl as github download ghdl is a fast and simple program (and als

Oct 12, 2022
🏃‍♂️ A new way to execute commands and manipulate command output in Go

??‍♂️ A new way to execute commands and manipulate command output in Go

Nov 11, 2022
A simple wrapper to daemonize Go applications.

daemonigo A simple library to daemonize Go programming language applications. Installing $ go get github.com/tyranron/daemonigo After this command da

Jul 15, 2022
Prometheus instrumentation library for Go applications

Prometheus Go client library This is the Go client library for Prometheus. It has two separate parts, one for instrumenting application code, and one

Jan 3, 2023
A simple Cron library for go that can execute closures or functions at varying intervals, from once a second to once a year on a specific date and time. Primarily for web applications and long running daemons.

Cron.go This is a simple library to handle scheduled tasks. Tasks can be run in a minimum delay of once a second--for which Cron isn't actually design

Dec 17, 2022
A BPMN engine, meant to be embedded in Go applications with minim hurdles, and a pleasant developer experience using it.

A BPMN engine, meant to be embedded in Go applications with minim hurdles, and a pleasant developer experience using it. This approach can increase transparency for non-developers.

Dec 29, 2022