Exemple #1
0
func Close(db Closer) {
	if db != nil {
		if err := db.Close(); err != nil {
			log.Warn(errors.As(err))
		}
	}
}
Exemple #2
0
func New() (*Engine, error) {
	engine, err := xorm.NewEngine(driver, dsn)
	if err != nil {
		return nil, errors.As(err)
	}

	// cache
	// cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
	// engine.SetDefaultCacher(cacher)

	return &Engine{engine}, nil
}
Exemple #3
0
func RegisterHttpHandler(router *mux.Router, path, method string, handler HttpHandler) {
	h := func(w http.ResponseWriter, r *http.Request) {
		// parseForm
		if err := r.ParseForm(); err != nil {
			log.Warn(errors.As(err))
		}

		// dump
		bytes, err := httputil.DumpRequest(r, true)
		if err != nil {
			log.Warn(err)
		} else {
			log.Debug(string(bytes))
		}

		dump := dumpHttpRequest(r)
		log.Debug(dump)

		t := time.Now()
		status, body := handler(r)
		writeHttpResp(w, dump, status, body, t)
	}
	router.HandleFunc(path, h).Methods(method)
}