diff --git a/middleware/error.go b/middleware/error.go index 726290ed..895e7b6f 100644 --- a/middleware/error.go +++ b/middleware/error.go @@ -257,7 +257,11 @@ func InternalServerError(rw http.ResponseWriter, r *http.Request) { t.Execute(rw, data) } -func registerErrorHander() { +func Errorhandler(err string, h http.HandlerFunc) { + ErrorMaps[err] = h +} + +func RegisterErrorHander() { if _, ok := ErrorMaps["404"]; !ok { ErrorMaps["404"] = NotFound } diff --git a/middleware/profile.go b/middleware/profile.go index 51e47f41..0bb09058 100644 --- a/middleware/profile.go +++ b/middleware/profile.go @@ -69,52 +69,6 @@ func DumpHeap() { f.Close() } -//func showSystemStat(interval time.Duration, count int) { - -// usage1 := &syscall.Rusage{} -// var lastUtime int64 -// var lastStime int64 - -// counter := 0 -// for { - -// //http://man7.org/linux/man-pages/man3/vtimes.3.html -// syscall.Getrusage(syscall.RUSAGE_SELF, usage1) - -// utime := (usage1.Utime.Sec * 1000000000) + int64(usage1.Utime.Usec) -// stime := (usage1.Stime.Sec * 1000000000) + int64(usage1.Stime.Usec) -// userCPUUtil := float64(utime-lastUtime) * 100 / float64(interval) -// sysCPUUtil := float64(stime-lastStime) * 100 / float64(interval) -// memUtil := usage1.Maxrss * 1024 - -// lastUtime = utime -// lastStime = stime - -// if counter > 0 { -// fmt.Printf("cpu: %3.2f%% us %3.2f%% sy, mem:%s \n", userCPUUtil, sysCPUUtil, toH(uint64(memUtil))) -// } - -// counter += 1 -// if count >= 1 && count < counter { -// return -// } -// time.Sleep(interval) -// } - -//} - -//func ShowSystemStat(seconds int) { -// go func() { -// interval := time.Duration(seconds) * time.Second -// showSystemStat(interval, 0) -// }() -//} - -//func PrintSystemStats() { -// interval := time.Duration(1) * time.Second -// showSystemStat(interval, 1) -//} - func ShowGCStat() { go func() { var numGC int64 diff --git a/middleware/session.go b/middleware/session.go deleted file mode 100644 index 48beba91..00000000 --- a/middleware/session.go +++ /dev/null @@ -1,14 +0,0 @@ -package middleware - -import ( - "github.com/astaxie/beego/session" -) - -var ( - GlobalSessions *session.Manager -) - -func StartSession(provideName, cookieName string, maxlifetime int64, savePath string) { - GlobalSessions, _ = session.NewManager(provideName, cookieName, maxlifetime, savePath) - go GlobalSessions.GC() -}