Categorygithub.com/kataras/go-errors
modulepackage
0.0.3
Repository: https://github.com/kataras/go-errors.git
Documentation: pkg.go.dev

# README

Build Status License Releases Read me docs Build Status Built with GoLang Platforms

This package provides a way to initialize possible errors and handle them with ease.

Installation

The only requirement is the Go Programming Language.

$ go get -u gopkg.in/kataras/go-errors.v0

Docs

New

New receives a message format and creates a new Error. Message format, which is created with .New, is never changes.

import "gopkg.in/kataras/go-errors.v0"

var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")

Format

Format is like fmt.Sprintf but for specific Error, returns a new error with the formatted message.

import "gopkg.in/kataras/go-errors.v0"

var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")

func anything() error {
  return errUserAlreadyJoined.Format("myusername")
  // will return an error with message =
  // User with username: myusername was already joined in this room!
  //
}

Append

Append and AppendErr adds a message to existing message and returns a new error.

import "gopkg.in/kataras/go-errors.v0"

var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")

func anything() error {
  return errUserAlreadyJoined.Append("Please specify other room.").Format("myusername")
  // will return an error with message =
  // User with username: myusername was already joined in this room!
  // Please specify other room.
  //
}
import "gopkg.in/kataras/go-errors.v0"

var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")
var errSpecifyOtherRoom  = errors.New("Please specify other room.")

func anything() error {
  return errUserAlreadyJoined.AppendErr(errSpecifyOtherRoom).Format("myusername")
  // will return an error with message =
  // User with username: myusername was already joined in this room!
  // Please specify other room.
  //
}

Use AppendErr with go standard error type

import (
  "gopkg.in/kataras/go-errors.v0"
  "fmt"
)

var errUserAlreadyJoined = errors.New("User with username: %s was already joined in this room!")

func anything() error {
  err := fmt.Errorf("Please specify other room") // standard golang error

  return errUserAlreadyJoined.AppendErr(err).Format("myusername")
  // will return an error with message =
  // User with username: myusername was already joined in this room!
  // Please specify other room.
  //
}

go-* packages

NameDescription
go-fsFileSystem utils and common net/http static files handlers
go-eventsEventEmmiter for Go
go-websocketA websocket server and ,optionally, client side lib for Go
go-sshSSH Server, build ssh interfaces, remote commands and remote cli with ease
go-gzipwriterWrite gzip data to a io.Writer
go-mailerE-mail Sender, send rich mails with one call
rizlaMonitor and live-reload of your Go App
QHTTP2 Web Framework, 100% compatible with net/http
IrisThe fastest web framework. Built on top of fasthttp

FAQ

Explore these questions or navigate to the community chat.

Versioning

Current: v0.0.3

People

The author of go-errors is @kataras.

If you're willing to donate, feel free to send any amount through paypal

Contributing

If you are interested in contributing to the go-errors project, please make a PR.

License

This project is licensed under the MIT License.

License can be found here.

# Functions

New creates and returns an Error with a pre-defined user output message all methods below that doesn't accept a pointer receiver because actualy they are not changing the original message.

# Constants

Version current version number.

# Variables

NewLine adds a new line to the end of each error's message defaults to true.
Prefix the error prefix, applies to each error's message defaults to Error:_.

# Structs

Error holds the error message, this message never really changes.