Exemple #1
0
const (
	HTTP_GET    = "GET"
	HTTP_POST   = "POST"
	HTTP_PUT    = "PUT"
	HTTP_DELETE = "DELETE"
)

const (
	OK               = "OK"
	JSON_EMPTY_ARRAY = "[]"
	JSON_EMPTY_OBJ   = "{}"
)

// -----------------------
var log = l.New("")

// -----------------------
// RegisterHttpHandler

type HttpHandler func(*http.Request) (string, interface{})

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)
Exemple #2
0
package db

import (
	"io"

	"common/errors"
	"common/etc"
	l "common/log"
	_ "github.com/go-sql-driver/mysql"
	"github.com/go-xorm/xorm"
)

var log = l.New("common/db")

var (
	driver = etc.String("datastore", "driver")
	dsn    = etc.String("datastore", "dsn")
)

// --------------
// Engine

type Engine struct {
	*xorm.Engine
}

func New() (*Engine, error) {
	engine, err := xorm.NewEngine(driver, dsn)
	if err != nil {
		return nil, errors.As(err)
	}
Exemple #3
0
package httpx

import (
	"net/http"
	"net/http/httputil"

	l "common/log"
)

var log = l.New("basis/httpx")

func DumpRequest(r *http.Request) {
	dump, err := httputil.DumpRequest(r, true)
	if err != nil {
		log.Info("dumpReq err:", err)
	} else {
		log.Info("dumpReq ok:", string(dump))
	}
}