mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 05:25:58 +00:00
update to version 8.4.1 ❤️ https://github.com/kataras/iris/blob/master/HISTORY.md#th-07-september-2017--v841
Former-commit-id: 9e5f0a08049b83605aa847b8f51fb856427354a6
This commit is contained in:
@@ -254,7 +254,12 @@ func (su *Supervisor) ListenAndServeTLS(certFile string, keyFile string) error {
|
||||
// manually inserted as pre-go 1.9 for any case.
|
||||
cfg.NextProtos = []string{"h2", "http/1.1"}
|
||||
su.Server.TLSConfig = cfg
|
||||
return su.ListenAndServe()
|
||||
|
||||
// It does nothing more than the su.Server.ListenAndServeTLS anymore.
|
||||
// - no hurt if we let it as it is
|
||||
// - no problem if we remove it as well
|
||||
// but let's comment this as proposed, fewer code is better:
|
||||
// return su.ListenAndServe()
|
||||
}
|
||||
|
||||
if su.Server.TLSConfig == nil {
|
||||
|
||||
@@ -181,6 +181,14 @@ func (r *Store) GetInt64(key string) (int64, error) {
|
||||
return strconv.ParseInt(r.GetString(key), 10, 64)
|
||||
}
|
||||
|
||||
// GetBool returns the user's value as bool, based on its key.
|
||||
// a string which is "1" or "t" or "T" or "TRUE" or "true" or "True"
|
||||
// or "0" or "f" or "F" or "FALSE" or "false" or "False".
|
||||
// Any other value returns an error.
|
||||
func (r *Store) GetBool(key string) (bool, error) {
|
||||
return strconv.ParseBool(key)
|
||||
}
|
||||
|
||||
// Remove deletes an entry linked to that "key",
|
||||
// returns true if an entry is actually removed.
|
||||
func (r *Store) Remove(key string) bool {
|
||||
|
||||
@@ -18,13 +18,18 @@ const (
|
||||
// Declaration: /mypath/{myparam:string} or /mypath{myparam}
|
||||
ParamTypeString
|
||||
// ParamTypeInt is the integer, a number type.
|
||||
// Allows only numbers (0-9)
|
||||
// Allows only possitive numbers (0-9)
|
||||
// Declaration: /mypath/{myparam:int}
|
||||
ParamTypeInt
|
||||
// ParamTypeLong is the integer, a number type.
|
||||
// Allows only numbers (0-9)
|
||||
// Allows only possitive numbers (0-9)
|
||||
// Declaration: /mypath/{myparam:long}
|
||||
ParamTypeLong
|
||||
// ParamTypeBoolean is the bool type.
|
||||
// Allows only "1" or "t" or "T" or "TRUE" or "true" or "True"
|
||||
// or "0" or "f" or "F" or "FALSE" or "false" or "False".
|
||||
// Declaration: /mypath/{myparam:boolean}
|
||||
ParamTypeBoolean
|
||||
// ParamTypeAlphabetical is the alphabetical/letter type type.
|
||||
// Allows letters only (upper or lowercase)
|
||||
// Declaration: /mypath/{myparam:alphabetical}
|
||||
@@ -49,6 +54,7 @@ var paramTypes = map[string]ParamType{
|
||||
"string": ParamTypeString,
|
||||
"int": ParamTypeInt,
|
||||
"long": ParamTypeLong,
|
||||
"boolean": ParamTypeBoolean,
|
||||
"alphabetical": ParamTypeAlphabetical,
|
||||
"file": ParamTypeFile,
|
||||
"path": ParamTypePath,
|
||||
|
||||
@@ -131,6 +131,13 @@ func TestParseParam(t *testing.T) {
|
||||
Type: ast.ParamTypeLong,
|
||||
ErrorCode: 404,
|
||||
}}, // 8
|
||||
{true,
|
||||
ast.ParamStatement{
|
||||
Src: "{has:boolean else 404}",
|
||||
Name: "has",
|
||||
Type: ast.ParamTypeBoolean,
|
||||
ErrorCode: 404,
|
||||
}}, // 9
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"unicode"
|
||||
|
||||
"github.com/kataras/iris/core/router/macro/interpreter/ast"
|
||||
@@ -208,17 +209,23 @@ func (m *Macro) getFunc(funcName string) ParamEvaluatorBuilder {
|
||||
|
||||
// Map contains the default macros mapped to their types.
|
||||
// This is the manager which is used by the caller to register custom
|
||||
// parameter functions per param-type (String, Int, Long, Alphabetical, File, Path).
|
||||
// parameter functions per param-type (String, Int, Long, Boolean, Alphabetical, File, Path).
|
||||
type Map struct {
|
||||
// string type
|
||||
// anything
|
||||
String *Macro
|
||||
// int type
|
||||
// only numbers (0-9)
|
||||
// uint type
|
||||
// only possitive numbers (+0-9)
|
||||
// it could be uint/uint32 but we keep int for simplicity
|
||||
Int *Macro
|
||||
// long an int64 type
|
||||
// only numbers (0-9)
|
||||
// only possitive numbers (+0-9)
|
||||
// it could be uint64 but we keep int64 for simplicity
|
||||
Long *Macro
|
||||
// boolean as bool type
|
||||
// a string which is "1" or "t" or "T" or "TRUE" or "true" or "True"
|
||||
// or "0" or "f" or "F" or "FALSE" or "false" or "False".
|
||||
Boolean *Macro
|
||||
// alphabetical/letter type
|
||||
// letters only (upper or lowercase)
|
||||
Alphabetical *Macro
|
||||
@@ -242,9 +249,15 @@ type Map struct {
|
||||
func NewMap() *Map {
|
||||
return &Map{
|
||||
// it allows everything, so no need for a regexp here.
|
||||
String: newMacro(func(string) bool { return true }),
|
||||
Int: newMacro(MustNewEvaluatorFromRegexp("^[0-9]+$")),
|
||||
Long: newMacro(MustNewEvaluatorFromRegexp("^[0-9]+$")),
|
||||
String: newMacro(func(string) bool { return true }),
|
||||
Int: newMacro(MustNewEvaluatorFromRegexp("^[0-9]+$")),
|
||||
Long: newMacro(MustNewEvaluatorFromRegexp("^[0-9]+$")),
|
||||
Boolean: newMacro(func(paramValue string) bool {
|
||||
// a simple if statement is faster than regex ^(true|false|True|False|t|0|f|FALSE|TRUE)$
|
||||
// in this case.
|
||||
_, err := strconv.ParseBool(paramValue)
|
||||
return err == nil
|
||||
}),
|
||||
Alphabetical: newMacro(MustNewEvaluatorFromRegexp("^[a-zA-Z ]+$")),
|
||||
File: newMacro(MustNewEvaluatorFromRegexp("^[a-zA-Z0-9_.-]*$")),
|
||||
// it allows everything, we have String and Path as different
|
||||
@@ -265,6 +278,8 @@ func (m *Map) Lookup(typ ast.ParamType) *Macro {
|
||||
return m.Int
|
||||
case ast.ParamTypeLong:
|
||||
return m.Long
|
||||
case ast.ParamTypeBoolean:
|
||||
return m.Boolean
|
||||
case ast.ParamTypeAlphabetical:
|
||||
return m.Alphabetical
|
||||
case ast.ParamTypeFile:
|
||||
|
||||
Reference in New Issue
Block a user