httplib: fix unstable test, do not use httplib.org
This commit is contained in:
@@ -17,16 +17,15 @@
|
||||
// type DatabaseCheck struct {
|
||||
// }
|
||||
//
|
||||
// func (dc *DatabaseCheck) Check() error {
|
||||
// if dc.isConnected() {
|
||||
// return nil
|
||||
// } else {
|
||||
// return errors.New("can't connect database")
|
||||
// }
|
||||
// }
|
||||
// func (dc *DatabaseCheck) Check() error {
|
||||
// if dc.isConnected() {
|
||||
// return nil
|
||||
// } else {
|
||||
// return errors.New("can't connect database")
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// AddHealthCheck("database",&DatabaseCheck{})
|
||||
//
|
||||
package admin
|
||||
|
||||
// AdminCheckList holds health checker map
|
||||
|
||||
@@ -14,29 +14,31 @@
|
||||
|
||||
// Package config is used to parse config.
|
||||
// Usage:
|
||||
// import "github.com/beego/beego/v2/core/config"
|
||||
//
|
||||
// import "github.com/beego/beego/v2/core/config"
|
||||
//
|
||||
// Examples.
|
||||
//
|
||||
// cnf, err := config.NewConfig("ini", "config.conf")
|
||||
// cnf, err := config.NewConfig("ini", "config.conf")
|
||||
//
|
||||
// cnf APIS:
|
||||
// cnf APIS:
|
||||
//
|
||||
// cnf.Set(key, val string) error
|
||||
// cnf.String(key string) string
|
||||
// cnf.Strings(key string) []string
|
||||
// cnf.Int(key string) (int, error)
|
||||
// cnf.Int64(key string) (int64, error)
|
||||
// cnf.Bool(key string) (bool, error)
|
||||
// cnf.Float(key string) (float64, error)
|
||||
// cnf.DefaultString(key string, defaultVal string) string
|
||||
// cnf.DefaultStrings(key string, defaultVal []string) []string
|
||||
// cnf.DefaultInt(key string, defaultVal int) int
|
||||
// cnf.DefaultInt64(key string, defaultVal int64) int64
|
||||
// cnf.DefaultBool(key string, defaultVal bool) bool
|
||||
// cnf.DefaultFloat(key string, defaultVal float64) float64
|
||||
// cnf.DIY(key string) (interface{}, error)
|
||||
// cnf.GetSection(section string) (map[string]string, error)
|
||||
// cnf.SaveConfigFile(filename string) error
|
||||
// cnf.Set(key, val string) error
|
||||
// cnf.String(key string) string
|
||||
// cnf.Strings(key string) []string
|
||||
// cnf.Int(key string) (int, error)
|
||||
// cnf.Int64(key string) (int64, error)
|
||||
// cnf.Bool(key string) (bool, error)
|
||||
// cnf.Float(key string) (float64, error)
|
||||
// cnf.DefaultString(key string, defaultVal string) string
|
||||
// cnf.DefaultStrings(key string, defaultVal []string) []string
|
||||
// cnf.DefaultInt(key string, defaultVal int) int
|
||||
// cnf.DefaultInt64(key string, defaultVal int64) int64
|
||||
// cnf.DefaultBool(key string, defaultVal bool) bool
|
||||
// cnf.DefaultFloat(key string, defaultVal float64) float64
|
||||
// cnf.DIY(key string) (interface{}, error)
|
||||
// cnf.GetSection(section string) (map[string]string, error)
|
||||
// cnf.SaveConfigFile(filename string) error
|
||||
package config
|
||||
|
||||
import (
|
||||
@@ -266,6 +268,7 @@ func ExpandValueEnvForMap(m map[string]interface{}) map[string]interface{} {
|
||||
//
|
||||
// It accept value formats "${env}" , "${env||}}" , "${env||defaultValue}" , "defaultvalue".
|
||||
// Examples:
|
||||
//
|
||||
// v1 := config.ExpandValueEnv("${GOPATH}") // return the GOPATH environment variable.
|
||||
// v2 := config.ExpandValueEnv("${GOAsta||/usr/local/go}") // return the default value "/usr/local/go/".
|
||||
// v3 := config.ExpandValueEnv("Astaxie") // return the value "Astaxie".
|
||||
|
||||
2
core/config/env/env_test.go
vendored
2
core/config/env/env_test.go
vendored
@@ -5,7 +5,7 @@
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
||||
@@ -19,13 +19,13 @@
|
||||
// go install github.com/beego/x2j.
|
||||
//
|
||||
// Usage:
|
||||
// import(
|
||||
// _ "github.com/beego/beego/v2/core/config/xml"
|
||||
// "github.com/beego/beego/v2/core/config"
|
||||
// )
|
||||
//
|
||||
// cnf, err := config.NewConfig("xml", "config.xml")
|
||||
// import(
|
||||
// _ "github.com/beego/beego/v2/core/config/xml"
|
||||
// "github.com/beego/beego/v2/core/config"
|
||||
// )
|
||||
//
|
||||
// cnf, err := config.NewConfig("xml", "config.xml")
|
||||
package xml
|
||||
|
||||
import (
|
||||
@@ -40,9 +40,10 @@ import (
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
|
||||
"github.com/beego/x2j"
|
||||
|
||||
"github.com/beego/beego/v2/core/config"
|
||||
"github.com/beego/beego/v2/core/logs"
|
||||
"github.com/beego/x2j"
|
||||
)
|
||||
|
||||
// Config is a xml config parser and implements Config interface.
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
|
||||
// Package yaml for config provider
|
||||
// Usage:
|
||||
// import(
|
||||
// _ "github.com/beego/beego/v2/core/config/yaml"
|
||||
// "github.com/beego/beego/v2/core/config"
|
||||
// )
|
||||
//
|
||||
// cnf, err := config.NewConfig("yaml", "config.yaml")
|
||||
// import(
|
||||
// _ "github.com/beego/beego/v2/core/config/yaml"
|
||||
// "github.com/beego/beego/v2/core/config"
|
||||
// )
|
||||
//
|
||||
// cnf, err := config.NewConfig("yaml", "config.yaml")
|
||||
package yaml
|
||||
|
||||
import (
|
||||
|
||||
@@ -110,15 +110,16 @@ func (w *fileLogWriter) SetFormatter(f LogFormatter) {
|
||||
|
||||
// Init file logger with json config.
|
||||
// jsonConfig like:
|
||||
// {
|
||||
// "filename":"logs/beego.log",
|
||||
// "maxLines":10000,
|
||||
// "maxsize":1024,
|
||||
// "daily":true,
|
||||
// "maxDays":15,
|
||||
// "rotate":true,
|
||||
// "perm":"0600"
|
||||
// }
|
||||
//
|
||||
// {
|
||||
// "filename":"logs/beego.log",
|
||||
// "maxLines":10000,
|
||||
// "maxsize":1024,
|
||||
// "daily":true,
|
||||
// "maxDays":15,
|
||||
// "rotate":true,
|
||||
// "perm":"0600"
|
||||
// }
|
||||
func (w *fileLogWriter) Init(config string) error {
|
||||
err := json.Unmarshal([]byte(config), w)
|
||||
if err != nil {
|
||||
|
||||
@@ -47,6 +47,7 @@ func newSMTPWriter() Logger {
|
||||
|
||||
// Init smtp writer with json config.
|
||||
// config like:
|
||||
//
|
||||
// {
|
||||
// "username":"example@gmail.com",
|
||||
// "password:"password",
|
||||
|
||||
@@ -2,53 +2,51 @@
|
||||
Package pagination provides utilities to setup a paginator within the
|
||||
context of a http request.
|
||||
|
||||
Usage
|
||||
# Usage
|
||||
|
||||
In your beego.Controller:
|
||||
|
||||
package controllers
|
||||
package controllers
|
||||
|
||||
import "github.com/beego/beego/v2/core/utils/pagination"
|
||||
import "github.com/beego/beego/v2/core/utils/pagination"
|
||||
|
||||
type PostsController struct {
|
||||
beego.Controller
|
||||
}
|
||||
type PostsController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
func (this *PostsController) ListAllPosts() {
|
||||
// sets this.Data["paginator"] with the current offset (from the url query param)
|
||||
postsPerPage := 20
|
||||
paginator := pagination.SetPaginator(this.Ctx, postsPerPage, CountPosts())
|
||||
|
||||
// fetch the next 20 posts
|
||||
this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage)
|
||||
}
|
||||
func (this *PostsController) ListAllPosts() {
|
||||
// sets this.Data["paginator"] with the current offset (from the url query param)
|
||||
postsPerPage := 20
|
||||
paginator := pagination.SetPaginator(this.Ctx, postsPerPage, CountPosts())
|
||||
|
||||
// fetch the next 20 posts
|
||||
this.Data["posts"] = ListPostsByOffsetAndLimit(paginator.Offset(), postsPerPage)
|
||||
}
|
||||
|
||||
In your view templates:
|
||||
|
||||
{{if .paginator.HasPages}}
|
||||
<ul class="pagination pagination">
|
||||
{{if .paginator.HasPrev}}
|
||||
<li><a href="{{.paginator.PageLinkFirst}}">{{ i18n .Lang "paginator.first_page"}}</a></li>
|
||||
<li><a href="{{.paginator.PageLinkPrev}}">«</a></li>
|
||||
{{else}}
|
||||
<li class="disabled"><a>{{ i18n .Lang "paginator.first_page"}}</a></li>
|
||||
<li class="disabled"><a>«</a></li>
|
||||
{{end}}
|
||||
{{range $index, $page := .paginator.Pages}}
|
||||
<li{{if $.paginator.IsActive .}} class="active"{{end}}>
|
||||
<a href="{{$.paginator.PageLink $page}}">{{$page}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
{{if .paginator.HasNext}}
|
||||
<li><a href="{{.paginator.PageLinkNext}}">»</a></li>
|
||||
<li><a href="{{.paginator.PageLinkLast}}">{{ i18n .Lang "paginator.last_page"}}</a></li>
|
||||
{{else}}
|
||||
<li class="disabled"><a>»</a></li>
|
||||
<li class="disabled"><a>{{ i18n .Lang "paginator.last_page"}}</a></li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{end}}
|
||||
|
||||
{{if .paginator.HasPages}}
|
||||
<ul class="pagination pagination">
|
||||
{{if .paginator.HasPrev}}
|
||||
<li><a href="{{.paginator.PageLinkFirst}}">{{ i18n .Lang "paginator.first_page"}}</a></li>
|
||||
<li><a href="{{.paginator.PageLinkPrev}}">«</a></li>
|
||||
{{else}}
|
||||
<li class="disabled"><a>{{ i18n .Lang "paginator.first_page"}}</a></li>
|
||||
<li class="disabled"><a>«</a></li>
|
||||
{{end}}
|
||||
{{range $index, $page := .paginator.Pages}}
|
||||
<li{{if $.paginator.IsActive .}} class="active"{{end}}>
|
||||
<a href="{{$.paginator.PageLink $page}}">{{$page}}</a>
|
||||
</li>
|
||||
{{end}}
|
||||
{{if .paginator.HasNext}}
|
||||
<li><a href="{{.paginator.PageLinkNext}}">»</a></li>
|
||||
<li><a href="{{.paginator.PageLinkLast}}">{{ i18n .Lang "paginator.last_page"}}</a></li>
|
||||
{{else}}
|
||||
<li class="disabled"><a>»</a></li>
|
||||
<li class="disabled"><a>{{ i18n .Lang "paginator.last_page"}}</a></li>
|
||||
{{end}}
|
||||
</ul>
|
||||
{{end}}
|
||||
*/
|
||||
package pagination
|
||||
|
||||
@@ -78,11 +78,11 @@ func (p *Paginator) Page() int {
|
||||
//
|
||||
// Usage (in a view template):
|
||||
//
|
||||
// {{range $index, $page := .paginator.Pages}}
|
||||
// <li{{if $.paginator.IsActive .}} class="active"{{end}}>
|
||||
// <a href="{{$.paginator.PageLink $page}}">{{$page}}</a>
|
||||
// </li>
|
||||
// {{end}}
|
||||
// {{range $index, $page := .paginator.Pages}}
|
||||
// <li{{if $.paginator.IsActive .}} class="active"{{end}}>
|
||||
// <a href="{{$.paginator.PageLink $page}}">{{$page}}</a>
|
||||
// </li>
|
||||
// {{end}}
|
||||
func (p *Paginator) Pages() []int {
|
||||
if p.pageRange == nil && p.nums > 0 {
|
||||
var pages []int
|
||||
|
||||
@@ -67,13 +67,15 @@ type CustomFunc func(v *Validation, obj interface{}, key string)
|
||||
|
||||
// AddCustomFunc Add a custom function to validation
|
||||
// The name can not be:
|
||||
// Clear
|
||||
// HasErrors
|
||||
// ErrorMap
|
||||
// Error
|
||||
// Check
|
||||
// Valid
|
||||
// NoMatch
|
||||
//
|
||||
// Clear
|
||||
// HasErrors
|
||||
// ErrorMap
|
||||
// Error
|
||||
// Check
|
||||
// Valid
|
||||
// NoMatch
|
||||
//
|
||||
// If the name is same with exists function, it will replace the origin valid function
|
||||
func AddCustomFunc(name string, f CustomFunc) error {
|
||||
if unFuncs[name] {
|
||||
|
||||
@@ -42,7 +42,6 @@
|
||||
// log.Println(v.Error.Key, v.Error.Message)
|
||||
// }
|
||||
// }
|
||||
//
|
||||
package validation
|
||||
|
||||
import (
|
||||
|
||||
@@ -64,26 +64,27 @@ var once sync.Once
|
||||
|
||||
// SetDefaultMessage set default messages
|
||||
// if not set, the default messages are
|
||||
// "Required": "Can not be empty",
|
||||
// "Min": "Minimum is %d",
|
||||
// "Max": "Maximum is %d",
|
||||
// "Range": "Range is %d to %d",
|
||||
// "MinSize": "Minimum size is %d",
|
||||
// "MaxSize": "Maximum size is %d",
|
||||
// "Length": "Required length is %d",
|
||||
// "Alpha": "Must be valid alpha characters",
|
||||
// "Numeric": "Must be valid numeric characters",
|
||||
// "AlphaNumeric": "Must be valid alpha or numeric characters",
|
||||
// "Match": "Must match %s",
|
||||
// "NoMatch": "Must not match %s",
|
||||
// "AlphaDash": "Must be valid alpha or numeric or dash(-_) characters",
|
||||
// "Email": "Must be a valid email address",
|
||||
// "IP": "Must be a valid ip address",
|
||||
// "Base64": "Must be valid base64 characters",
|
||||
// "Mobile": "Must be valid mobile number",
|
||||
// "Tel": "Must be valid telephone number",
|
||||
// "Phone": "Must be valid telephone or mobile phone number",
|
||||
// "ZipCode": "Must be valid zipcode",
|
||||
//
|
||||
// "Required": "Can not be empty",
|
||||
// "Min": "Minimum is %d",
|
||||
// "Max": "Maximum is %d",
|
||||
// "Range": "Range is %d to %d",
|
||||
// "MinSize": "Minimum size is %d",
|
||||
// "MaxSize": "Maximum size is %d",
|
||||
// "Length": "Required length is %d",
|
||||
// "Alpha": "Must be valid alpha characters",
|
||||
// "Numeric": "Must be valid numeric characters",
|
||||
// "AlphaNumeric": "Must be valid alpha or numeric characters",
|
||||
// "Match": "Must match %s",
|
||||
// "NoMatch": "Must not match %s",
|
||||
// "AlphaDash": "Must be valid alpha or numeric or dash(-_) characters",
|
||||
// "Email": "Must be a valid email address",
|
||||
// "IP": "Must be a valid ip address",
|
||||
// "Base64": "Must be valid base64 characters",
|
||||
// "Mobile": "Must be valid mobile number",
|
||||
// "Tel": "Must be valid telephone number",
|
||||
// "Phone": "Must be valid telephone or mobile phone number",
|
||||
// "ZipCode": "Must be valid zipcode",
|
||||
func SetDefaultMessage(msg map[string]string) {
|
||||
if len(msg) == 0 {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user