Giter Club home page Giter Club logo

trash's Introduction

trash GoDoc Build Status

What is trash ?

trash deal with logging, sending and stacking errors. Currently supporting json and xml format. And also implementing the standard error interface.

alt tag

Example

Creating a new err.

  import "log"
  import "errors"

  func main() {
    // Takes a logger and data format (json, xml)
    t := trash.New(logger, "json")

    if 1 != 2 {
      // Default Err
      // Arguments (Error Type, Error Message) -> (string, string or error)
      t.NewErr(trash.GenericErr, errors.New("example err")).Send(rw).Log()

      // HTTP Err
      t.NewErr(trash.GenericErr, "useless error").SendHTTP(rw, 404).LogHTTP(req)

      // Standalone inline HTTP error declaring
      trash.NewJSONErr(trash.InvalidDataErr, "1 not equal 2 ...").LogHTTP(req).SendHTTP(rw, 406)
    }
  }

You can also create a dump. Which is an error stack you want to backup. A dump need a io.Writer to save the errors stack.

  func main() {
    t := trash.New(logger, "json")
    t2 := trash.New(logger, "xml")
    // The dump will write all errors from the provided trash in a log file or any io.Writer.
    trash.NewDump(file, t, t2)

    if 1 != 2 {
      t.NewErr(trash.InvalidDataErr, "1 not equal 2")
    }
}

TODO

  • DOC
  • More Testing
  • Debugging
  • Optimisation

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Write Tests!
  4. Commit your changes (git commit -am 'Add some feature')
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.