Beispiel #1
0
func ac_uploadtx(w http.ResponseWriter, r *http.Request) {
	imgdata, _ := ioutil.ReadAll(r.Body)
	userid := model.User_curuserid(w, r)
	imgname := "static\\touxiang\\" + userid + ".jpg"
	f, _ := os.Create(imgname)
	f.Write(imgdata)
	f.Close()

	file, _ := os.Open(imgname)
	img, _ := jpeg.Decode(file)
	file.Close()
	rm := resize.Resize(100, 100, img, resize.Lanczos3)
	out, _ := os.Create(imgname)
	defer out.Close()
	jpeg.Encode(out, rm, nil)
	model.Face(userid)
}
Beispiel #2
0
//错误句柄
func AppHandler(fn http.HandlerFunc, role ...int) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		if len(role) > 0 {
			if role[0] == 1 {
				id := model.User_curuserid(w, r)
				if id == "" {
					ExitMsg(w, "请先登录", "/user/login")
					return
				}
			}
		}

		defer func() {
			if err, ok := recover().(error); ok {
				fmt.Fprint(w, err)
			}
		}()
		fn(w, r)
	}
}