httplib: fix unstable test, do not use httplib.org
This commit is contained in:
@@ -30,7 +30,8 @@ var beeAdminApp *adminApp
|
||||
// FilterMonitorFunc is default monitor filter when admin module is enable.
|
||||
// if this func returns, admin module records qps for this request by condition of this function logic.
|
||||
// usage:
|
||||
// func MyFilterMonitor(method, requestPath string, t time.Duration, pattern string, statusCode int) bool {
|
||||
//
|
||||
// func MyFilterMonitor(method, requestPath string, t time.Duration, pattern string, statusCode int) bool {
|
||||
// if method == "POST" {
|
||||
// return false
|
||||
// }
|
||||
@@ -41,8 +42,8 @@ var beeAdminApp *adminApp
|
||||
// return false
|
||||
// }
|
||||
// return true
|
||||
// }
|
||||
// beego.FilterMonitorFunc = MyFilterMonitor.
|
||||
// }
|
||||
// beego.FilterMonitorFunc = MyFilterMonitor.
|
||||
var FilterMonitorFunc func(string, string, time.Duration, string, int) bool
|
||||
|
||||
func init() {
|
||||
|
||||
@@ -19,32 +19,35 @@
|
||||
// package controllers
|
||||
//
|
||||
// import (
|
||||
// "github.com/beego/beego/v2"
|
||||
// "github.com/beego/beego/v2/client/cache"
|
||||
// "github.com/beego/beego/v2/server/web/captcha"
|
||||
//
|
||||
// "github.com/beego/beego/v2"
|
||||
// "github.com/beego/beego/v2/client/cache"
|
||||
// "github.com/beego/beego/v2/server/web/captcha"
|
||||
//
|
||||
// )
|
||||
//
|
||||
// var cpt *captcha.Captcha
|
||||
//
|
||||
// func init() {
|
||||
// // use beego cache system store the captcha data
|
||||
// store := cache.NewMemoryCache()
|
||||
// cpt = captcha.NewWithFilter("/captcha/", store)
|
||||
// }
|
||||
// func init() {
|
||||
// // use beego cache system store the captcha data
|
||||
// store := cache.NewMemoryCache()
|
||||
// cpt = captcha.NewWithFilter("/captcha/", store)
|
||||
// }
|
||||
//
|
||||
// type MainController struct {
|
||||
// beego.Controller
|
||||
// }
|
||||
// type MainController struct {
|
||||
// beego.Controller
|
||||
// }
|
||||
//
|
||||
// func (this *MainController) Get() {
|
||||
// this.TplName = "index.tpl"
|
||||
// }
|
||||
// func (this *MainController) Get() {
|
||||
// this.TplName = "index.tpl"
|
||||
// }
|
||||
//
|
||||
// func (this *MainController) Post() {
|
||||
// this.TplName = "index.tpl"
|
||||
// func (this *MainController) Post() {
|
||||
// this.TplName = "index.tpl"
|
||||
//
|
||||
// this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
|
||||
// }
|
||||
//
|
||||
// this.Data["Success"] = cpt.VerifyReq(this.Ctx.Request)
|
||||
// }
|
||||
// ```
|
||||
//
|
||||
// template usage
|
||||
@@ -52,8 +55,10 @@
|
||||
// ```
|
||||
// {{.Success}}
|
||||
// <form action="/" method="post">
|
||||
// {{create_captcha}}
|
||||
// <input name="captcha" type="text">
|
||||
//
|
||||
// {{create_captcha}}
|
||||
// <input name="captcha" type="text">
|
||||
//
|
||||
// </form>
|
||||
// ```
|
||||
package captcha
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
// import "github.com/beego/beego/v2/server/web/context"
|
||||
//
|
||||
// ctx := context.Context{Request:req,ResponseWriter:rw}
|
||||
//
|
||||
package context
|
||||
|
||||
import (
|
||||
|
||||
@@ -635,31 +635,33 @@ func (c *Controller) GetFile(key string) (multipart.File, *multipart.FileHeader,
|
||||
|
||||
// GetFiles return multi-upload files
|
||||
// files, err:=c.GetFiles("myfiles")
|
||||
//
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusNoContent)
|
||||
// return
|
||||
// }
|
||||
// for i, _ := range files {
|
||||
// //for each fileheader, get a handle to the actual file
|
||||
// file, err := files[i].Open()
|
||||
// defer file.Close()
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
// return
|
||||
//
|
||||
// for i, _ := range files {
|
||||
// //for each fileheader, get a handle to the actual file
|
||||
// file, err := files[i].Open()
|
||||
// defer file.Close()
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// //create destination file making sure the path is writeable.
|
||||
// dst, err := os.Create("upload/" + files[i].Filename)
|
||||
// defer dst.Close()
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// //copy the uploaded file to the destination file
|
||||
// if _, err := io.Copy(dst, file); err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
// //create destination file making sure the path is writeable.
|
||||
// dst, err := os.Create("upload/" + files[i].Filename)
|
||||
// defer dst.Close()
|
||||
// if err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// //copy the uploaded file to the destination file
|
||||
// if _, err := io.Copy(dst, file); err != nil {
|
||||
// http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
// return
|
||||
// }
|
||||
// }
|
||||
func (c *Controller) GetFiles(key string) ([]*multipart.FileHeader, error) {
|
||||
if files, ok := c.Ctx.Request.MultipartForm.File[key]; ok {
|
||||
return files, nil
|
||||
|
||||
@@ -11,6 +11,5 @@ beego is inspired by Tornado, Sinatra and Flask with the added benefit of some G
|
||||
func main() {
|
||||
beego.Run()
|
||||
}
|
||||
|
||||
*/
|
||||
package web
|
||||
|
||||
@@ -386,7 +386,8 @@ func responseError(rw http.ResponseWriter, r *http.Request, errCode int, errCont
|
||||
|
||||
// ErrorHandler registers http.HandlerFunc to each http err code string.
|
||||
// usage:
|
||||
// beego.ErrorHandler("404",NotFound)
|
||||
//
|
||||
// beego.ErrorHandler("404",NotFound)
|
||||
// beego.ErrorHandler("500",InternalServerError)
|
||||
func ErrorHandler(code string, h http.HandlerFunc) *HttpServer {
|
||||
ErrorMaps[code] = &errorInfo{
|
||||
@@ -399,7 +400,8 @@ func ErrorHandler(code string, h http.HandlerFunc) *HttpServer {
|
||||
|
||||
// ErrorController registers ControllerInterface to each http err code string.
|
||||
// usage:
|
||||
// beego.ErrorController(&controllers.ErrorController{})
|
||||
//
|
||||
// beego.ErrorController(&controllers.ErrorController{})
|
||||
func ErrorController(c ControllerInterface) *HttpServer {
|
||||
reflectVal := reflect.ValueOf(c)
|
||||
rt := reflectVal.Type()
|
||||
|
||||
@@ -43,8 +43,8 @@ type FilterRouter struct {
|
||||
}
|
||||
|
||||
// params is for:
|
||||
// 1. setting the returnOnOutput value (false allows multiple filters to execute)
|
||||
// 2. determining whether or not params need to be reset.
|
||||
// 1. setting the returnOnOutput value (false allows multiple filters to execute)
|
||||
// 2. determining whether or not params need to be reset.
|
||||
func newFilterRouter(pattern string, filter FilterFunc, opts ...FilterOpt) *FilterRouter {
|
||||
mr := &FilterRouter{
|
||||
tree: NewTree(),
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
// Package apiauth provides handlers to enable apiauth support.
|
||||
//
|
||||
// Simple Usage:
|
||||
//
|
||||
// import(
|
||||
// "github.com/beego/beego/v2"
|
||||
// "github.com/beego/beego/v2/server/web/filter/apiauth"
|
||||
@@ -37,11 +38,11 @@
|
||||
//
|
||||
// Information:
|
||||
//
|
||||
// In the request user should include these params in the query
|
||||
// # In the request user should include these params in the query
|
||||
//
|
||||
// 1. appid
|
||||
//
|
||||
// appid is assigned to the application
|
||||
// appid is assigned to the application
|
||||
//
|
||||
// 2. signature
|
||||
//
|
||||
@@ -51,8 +52,7 @@
|
||||
//
|
||||
// 3. timestamp:
|
||||
//
|
||||
// send the request time, the format is yyyy-mm-dd HH:ii:ss
|
||||
//
|
||||
// send the request time, the format is yyyy-mm-dd HH:ii:ss
|
||||
package apiauth
|
||||
|
||||
import (
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
// Package auth provides handlers to enable basic auth support.
|
||||
// Simple Usage:
|
||||
//
|
||||
// import(
|
||||
// "github.com/beego/beego/v2"
|
||||
// "github.com/beego/beego/v2/server/web/filter/auth"
|
||||
@@ -25,7 +26,6 @@
|
||||
// beego.Run()
|
||||
// }
|
||||
//
|
||||
//
|
||||
// Advanced Usage:
|
||||
//
|
||||
// func SecretAuth(username, password string) bool {
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
|
||||
// Package authz provides handlers to enable ACL, RBAC, ABAC authorization support.
|
||||
// Simple Usage:
|
||||
//
|
||||
// import(
|
||||
// "github.com/beego/beego/v2"
|
||||
// "github.com/beego/beego/v2/server/web/filter/authz"
|
||||
@@ -26,7 +27,6 @@
|
||||
// beego.Run()
|
||||
// }
|
||||
//
|
||||
//
|
||||
// Advanced Usage:
|
||||
//
|
||||
// func main(){
|
||||
|
||||
@@ -14,9 +14,11 @@
|
||||
|
||||
// Package cors provides handlers to enable CORS support.
|
||||
// Usage
|
||||
//
|
||||
// import (
|
||||
// "github.com/beego/beego/v2"
|
||||
// "github.com/beego/beego/v2"
|
||||
// "github.com/beego/beego/v2/server/web/filter/cors"
|
||||
//
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
|
||||
@@ -18,28 +18,30 @@
|
||||
// Usage:
|
||||
//
|
||||
// import(
|
||||
// "log"
|
||||
// "net/http"
|
||||
// "os"
|
||||
//
|
||||
// "github.com/beego/beego/v2/server/web/grace"
|
||||
// "log"
|
||||
// "net/http"
|
||||
// "os"
|
||||
//
|
||||
// "github.com/beego/beego/v2/server/web/grace"
|
||||
//
|
||||
// )
|
||||
//
|
||||
// func handler(w http.ResponseWriter, r *http.Request) {
|
||||
// w.Write([]byte("WORLD!"))
|
||||
// }
|
||||
// func handler(w http.ResponseWriter, r *http.Request) {
|
||||
// w.Write([]byte("WORLD!"))
|
||||
// }
|
||||
//
|
||||
// func main() {
|
||||
// mux := http.NewServeMux()
|
||||
// mux.HandleFunc("/hello", handler)
|
||||
// func main() {
|
||||
// mux := http.NewServeMux()
|
||||
// mux.HandleFunc("/hello", handler)
|
||||
//
|
||||
// err := grace.ListenAndServe("localhost:8080", mux)
|
||||
// if err != nil {
|
||||
// log.Println(err)
|
||||
// }
|
||||
// log.Println("Server on 8080 stopped")
|
||||
// os.Exit(0)
|
||||
// }
|
||||
// err := grace.ListenAndServe("localhost:8080", mux)
|
||||
// if err != nil {
|
||||
// log.Println(err)
|
||||
// }
|
||||
// log.Println("Server on 8080 stopped")
|
||||
// os.Exit(0)
|
||||
// }
|
||||
package grace
|
||||
|
||||
import (
|
||||
|
||||
@@ -47,12 +47,14 @@ func NewNamespace(prefix string, params ...LinkNamespace) *Namespace {
|
||||
// Cond set condition function
|
||||
// if cond return true can run this namespace, else can't
|
||||
// usage:
|
||||
// ns.Cond(func (ctx *context.Context) bool{
|
||||
// if ctx.Input.Domain() == "api.beego.vip" {
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
// })
|
||||
//
|
||||
// ns.Cond(func (ctx *context.Context) bool{
|
||||
// if ctx.Input.Domain() == "api.beego.vip" {
|
||||
// return true
|
||||
// }
|
||||
// return false
|
||||
// })
|
||||
//
|
||||
// Cond as the first filter
|
||||
func (n *Namespace) Cond(cond namespaceCond) *Namespace {
|
||||
fn := func(ctx *beecontext.Context) {
|
||||
@@ -77,12 +79,13 @@ func (n *Namespace) Cond(cond namespaceCond) *Namespace {
|
||||
// action has before & after
|
||||
// FilterFunc
|
||||
// usage:
|
||||
// Filter("before", func (ctx *context.Context){
|
||||
// _, ok := ctx.Input.Session("uid").(int)
|
||||
// if !ok && ctx.Request.RequestURI != "/login" {
|
||||
// ctx.Redirect(302, "/login")
|
||||
// }
|
||||
// })
|
||||
//
|
||||
// Filter("before", func (ctx *context.Context){
|
||||
// _, ok := ctx.Input.Session("uid").(int)
|
||||
// if !ok && ctx.Request.RequestURI != "/login" {
|
||||
// ctx.Redirect(302, "/login")
|
||||
// }
|
||||
// })
|
||||
func (n *Namespace) Filter(action string, filter ...FilterFunc) *Namespace {
|
||||
var a int
|
||||
if action == "before" {
|
||||
@@ -239,18 +242,20 @@ func (n *Namespace) CtrlAny(rootpath string, f interface{}) *Namespace {
|
||||
// usage:
|
||||
// ns := beego.NewNamespace(“/v1”).
|
||||
// Namespace(
|
||||
// beego.NewNamespace("/shop").
|
||||
// Get("/:id", func(ctx *context.Context) {
|
||||
// ctx.Output.Body([]byte("shopinfo"))
|
||||
// }),
|
||||
// beego.NewNamespace("/order").
|
||||
// Get("/:id", func(ctx *context.Context) {
|
||||
// ctx.Output.Body([]byte("orderinfo"))
|
||||
// }),
|
||||
// beego.NewNamespace("/crm").
|
||||
// Get("/:id", func(ctx *context.Context) {
|
||||
// ctx.Output.Body([]byte("crminfo"))
|
||||
// }),
|
||||
//
|
||||
// beego.NewNamespace("/shop").
|
||||
// Get("/:id", func(ctx *context.Context) {
|
||||
// ctx.Output.Body([]byte("shopinfo"))
|
||||
// }),
|
||||
// beego.NewNamespace("/order").
|
||||
// Get("/:id", func(ctx *context.Context) {
|
||||
// ctx.Output.Body([]byte("orderinfo"))
|
||||
// }),
|
||||
// beego.NewNamespace("/crm").
|
||||
// Get("/:id", func(ctx *context.Context) {
|
||||
// ctx.Output.Body([]byte("crminfo"))
|
||||
// }),
|
||||
//
|
||||
// )
|
||||
func (n *Namespace) Namespace(ns ...*Namespace) *Namespace {
|
||||
for _, ni := range ns {
|
||||
|
||||
@@ -16,14 +16,15 @@
|
||||
//
|
||||
// Usage:
|
||||
// import(
|
||||
// "github.com/beego/beego/v2/server/web/session"
|
||||
//
|
||||
// "github.com/beego/beego/v2/server/web/session"
|
||||
//
|
||||
// )
|
||||
//
|
||||
// func init() {
|
||||
// globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "cookieLifeTime": 3600, "providerConfig": ""}`)
|
||||
// go globalSessions.GC()
|
||||
// }
|
||||
//
|
||||
// func init() {
|
||||
// globalSessions, _ = session.NewManager("memory", `{"cookieName":"gosessionid", "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false, "cookieLifeTime": 3600, "providerConfig": ""}`)
|
||||
// go globalSessions.GC()
|
||||
// }
|
||||
package session
|
||||
|
||||
import (
|
||||
|
||||
@@ -227,21 +227,21 @@ func Htmlunquote(text string) string {
|
||||
}
|
||||
|
||||
// URLFor returns url string with another registered controller handler with params.
|
||||
// usage:
|
||||
//
|
||||
// URLFor(".index")
|
||||
// print URLFor("index")
|
||||
// router /login
|
||||
// print URLFor("login")
|
||||
// print URLFor("login", "next","/"")
|
||||
// router /profile/:username
|
||||
// print UrlFor("profile", ":username","John Doe")
|
||||
// result:
|
||||
// /
|
||||
// /login
|
||||
// /login?next=/
|
||||
// /user/John%20Doe
|
||||
// usage:
|
||||
//
|
||||
// URLFor(".index")
|
||||
// print URLFor("index")
|
||||
// router /login
|
||||
// print URLFor("login")
|
||||
// print URLFor("login", "next","/"")
|
||||
// router /profile/:username
|
||||
// print UrlFor("profile", ":username","John Doe")
|
||||
// result:
|
||||
// /
|
||||
// /login
|
||||
// /login?next=/
|
||||
// /user/John%20Doe
|
||||
func URLFor(endpoint string, values ...interface{}) string {
|
||||
return BeeApp.Handlers.URLFor(endpoint, values...)
|
||||
}
|
||||
@@ -564,12 +564,13 @@ func ge(arg1, arg2 interface{}) (bool, error) {
|
||||
|
||||
// MapGet getting value from map by keys
|
||||
// usage:
|
||||
// Data["m"] = M{
|
||||
// "a": 1,
|
||||
// "1": map[string]float64{
|
||||
// "c": 4,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// Data["m"] = M{
|
||||
// "a": 1,
|
||||
// "1": map[string]float64{
|
||||
// "c": 4,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// {{ map_get m "a" }} // return 1
|
||||
// {{ map_get m 1 "c" }} // return 4
|
||||
|
||||
Reference in New Issue
Block a user