announcer

package module
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2021 License: Apache-2.0 Imports: 8 Imported by: 0

README

Go-announcer

Go-announcer lets you output information, warning or errors with optional key-value contexts.

Install

go get github.com/nicholastcs/go-announcer

Feature

  • Auto word-wrapping if the announcement string is long

  • Automatically emit to stderr if use ann.Error(...)

  • Emphasis bar prepend before messages, color and bar symbol changes when use ann.Warn(...) or ann.Error(...)

Examples

Basic

ann := announcer.New()

// simple announcement
ann.Tell("Discarded value")

// ... with context
ann.Tell("Authentication success", announcer.Args().
        AddContext("Session-ID", sId).
        AddContext("Role", userRole))

// warning announcement
ann.Warn("Limited access", announcer.Args().
        AddContext("Session-ID", sId))

// error announcement, third argument in .AddContext(...)
// will colorize Cause to red, if true.
ann.Error("Unauthorized access", announcer.Args().
        AddContext("Cause", err.Error(), true))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Redirect added in v0.0.3

func Redirect(w io.Writer) error

Redirect stream to a io.Writer instead of stdout or stderr.

Types

type AnnouncementArgs added in v0.0.3

type AnnouncementArgs struct {
	// contains filtered or unexported fields
}

AnnouncementArgs stores contexts.

func Args added in v0.0.3

func Args() *AnnouncementArgs

Args initialize AnnouncementArgs with empty context.

func (*AnnouncementArgs) AddContext added in v0.0.3

func (cb *AnnouncementArgs) AddContext(field string, value string, emphasize ...bool) *AnnouncementArgs

AddContext adds key-valued context to the announcement.

type Announcer

type Announcer struct {
	// contains filtered or unexported fields
}

Announcer is the struct that prints announcement to console or terminal.

func New

func New() *Announcer

New instantiates Announcer struct with sensible defaults. Currently the API does not expose any means to customize the Formatting or symbols.

func (*Announcer) Error

func (ann *Announcer) Error(msg string, cb ...*AnnouncementArgs)

Error tells a error. Emphasis bar is red. Emits in stderr.

func (*Announcer) Tell

func (ann *Announcer) Tell(msg string, cb ...*AnnouncementArgs)

Tell tells an announcement.

func (*Announcer) Warn

func (ann *Announcer) Warn(msg string, cb ...*AnnouncementArgs)

Warn tells a warning. Emphasis bar is yellow color.

type Context

type Context struct {
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL