mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-23 17:41:05 +01:00
v0.5.0-rc5: added proxy.exclude label, refactored some code
This commit is contained in:
@@ -20,16 +20,16 @@ func FormatDuration(d time.Duration) string {
|
||||
var parts []string
|
||||
|
||||
if days > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d Day%s", days, pluralize(days)))
|
||||
parts = append(parts, fmt.Sprintf("%d day%s", days, pluralize(days)))
|
||||
}
|
||||
if hours > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d Hour%s", hours, pluralize(hours)))
|
||||
parts = append(parts, fmt.Sprintf("%d hour%s", hours, pluralize(hours)))
|
||||
}
|
||||
if minutes > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d Minute%s", minutes, pluralize(minutes)))
|
||||
parts = append(parts, fmt.Sprintf("%d minute%s", minutes, pluralize(minutes)))
|
||||
}
|
||||
if seconds > 0 {
|
||||
parts = append(parts, fmt.Sprintf("%d Second%s", seconds, pluralize(seconds)))
|
||||
parts = append(parts, fmt.Sprintf("%d second%s", seconds, pluralize(seconds)))
|
||||
}
|
||||
|
||||
// Join the parts with appropriate connectors
|
||||
@@ -42,6 +42,15 @@ func FormatDuration(d time.Duration) string {
|
||||
return strings.Join(parts[:len(parts)-1], ", ") + " and " + parts[len(parts)-1]
|
||||
}
|
||||
|
||||
func ParseBool(s string) bool {
|
||||
switch strings.ToLower(s) {
|
||||
case "1", "true", "yes", "on":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func pluralize(n int64) string {
|
||||
if n > 1 {
|
||||
return "s"
|
||||
|
||||
@@ -2,7 +2,6 @@ package utils
|
||||
|
||||
import (
|
||||
"github.com/santhosh-tekuri/jsonschema"
|
||||
"github.com/yusing/go-proxy/common"
|
||||
)
|
||||
|
||||
var schemaCompiler = func() *jsonschema.Compiler {
|
||||
@@ -11,16 +10,13 @@ var schemaCompiler = func() *jsonschema.Compiler {
|
||||
return c
|
||||
}()
|
||||
|
||||
var schemaStorage = make(map[string] *jsonschema.Schema)
|
||||
var schemaStorage = make(map[string]*jsonschema.Schema)
|
||||
|
||||
func GetSchema(path string) *jsonschema.Schema {
|
||||
if common.NoSchemaValidation {
|
||||
panic("bug: GetSchema called when schema validation disabled")
|
||||
}
|
||||
if schema, ok := schemaStorage[path]; ok {
|
||||
return schema
|
||||
}
|
||||
schema := schemaCompiler.MustCompile(path)
|
||||
schemaStorage[path] = schema
|
||||
return schema
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user