Ejemplo n.º 1
0
func main() {
	// Create a new trash
	file, _ := os.Create("err_log.txt")
	t := trash.New(trash.DefaultLogger, "xml")
	trash.NewDump(file, t)

	http.HandleFunc("/xml", func(rw http.ResponseWriter, req *http.Request) {
		// Err with config
		t.NewHTTPErr(trash.GenericErr, "Test Error").SendHTTP(rw, 404).LogHTTP(req)
	})

	http.HandleFunc("/json", func(rw http.ResponseWriter, req *http.Request) {
		// Standalone JsonErr
		trash.NewJSONErr(trash.BadRequestErr, errors.New("Json Err !!")).SendHTTP(rw, 401).LogHTTP(req)
	})

	http.HandleFunc("/error", func(w http.ResponseWriter, r *http.Request) {
		createError("error interface from" + r.RemoteAddr)
	})

	http.HandleFunc("/local", func(rw http.ResponseWriter, req *http.Request) {
		t.NewErr(trash.BadRequestErr, "local error").Log()
	})

	http.HandleFunc("/short", func(rw http.ResponseWriter, req *http.Request) {
		t.NewShortErr(trash.GenericErr, "short Err", rw)
	})

	http.ListenAndServe(":8080", nil)
}
Ejemplo n.º 2
0
Archivo: api.go Proyecto: squiidz/spoon
package api

import (
	"log"
	"os"

	"github.com/go-zoo/trash"
	"gopkg.in/mgo.v2"
)

var (
	session = &mgo.Session{}
	db      = &mgo.Database{}
	errLog  = trash.New(log.New(os.Stdout, "<!SPOON!> ", 0), "json")
)

func init() {
	session, err := mgo.Dial("localhost:27017")
	if err != nil {
		errLog.NewErr("NO DB CONNECTION", err).Log()
		return
	}
	db = session.DB("spoon")
}