Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ gn Public

It is a utility package for gnames projects

License

gnames/gn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gn

User-friendly messaging and error handling for Go with colorized output.

Installation

go get github.com/gnames/gn

Usage

Messages

import "github.com/gnames/gn"

gn.Message("Processing data...")           // no icon
gn.Info("Server started on port %d", 8080) // ℹ️
gn.Warn("Connection timeout")              // ⚠️
gn.Success("All tests passed!")            // ✅
gn.Progress("Downloading files...")        // ⏳

Inline Formatting

gn.Info("Starting <title>Production Server</title>")
gn.Message("Found <em>42</em> records")
gn.Info("Status: <warn>degraded</warn>")
gn.Info("Errors: <err>3</err>")

Available tags:

  • <title>...</title> - green with ** emphasis
  • <em>...</em> - green
  • <warn>...</warn> - yellow
  • <err>...</err> - red

Custom Errors

const (
    ErrDatabase gn.ErrorCode = 1000
    ErrNetwork  gn.ErrorCode = 2000
)

err := &gn.Error{
    Code: ErrDatabase,
    Err:  errors.New("connection failed"),
    Msg:  "Could not connect to database: %s",
    Vars: []any{"postgres"},
}

gn.PrintErrorMessage(err) // ❌ Could not connect to database: postgres

// Works with standard error handling
var gnErr *gn.Error
if errors.As(err, &gnErr) {
    fmt.Printf("Error code: %d\n", gnErr.Code)
}

License

See LICENSE file.

About

It is a utility package for gnames projects

Resources

License

Stars

Watchers

Forks

Packages

No packages published