commit 70207f8e0128ca7ac370385e6baf0ae33846df1a Author: Charles Iliya Krempeaux Date: Fri Nov 19 15:41:30 2021 -0800 initial commits diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..a55341f --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2021 Charles Iliya Krempeaux :: http://changelog.ca/ + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..4d3fa3a --- /dev/null +++ b/README.md @@ -0,0 +1,24 @@ +# go-fck + +Package **fck** implements tools to create and manipulate errors. + +## Documention + +Online documentation, which includes examples, can be found at: http://godoc.org/github.com/reiver/go-fck + +[![GoDoc](https://godoc.org/github.com/reiver/go-fck?status.svg)](https://godoc.org/github.com/reiver/go-fck) + +## Creating Errors + +There are two ways to create errors — + +With `fck.Error`: +``` + const err error = fck.Error("internal-error") +``` +And with `fck.Errorf`: +``` + const err error = fck.Errorf("bad value for id %q", id) +``` + +**One thing to notice is that `fck.Error` errors can be a Go `const`.** diff --git a/error.go b/error.go new file mode 100644 index 0000000..47000ac --- /dev/null +++ b/error.go @@ -0,0 +1,9 @@ +package fck + +type Error string + +func (receiver Error) Error() string { + return string(receiver) +} + +var _ error = Error("") diff --git a/errorf.go b/errorf.go new file mode 100644 index 0000000..114b33d --- /dev/null +++ b/errorf.go @@ -0,0 +1,12 @@ +package fck + +import ( + "fmt" +) + +func Errorf(format string, a ...interface{}) error { + + var s string =fmt.Sprintf(format, a...) + + return Error(s) +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..e3ed452 --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module github.com/reiver/go-fck + +go 1.17