v0.5.0-rc5: added proxy.exclude label, refactored some code

This commit is contained in:
yusing
2024-09-17 17:56:41 +08:00
parent 83d1d027c6
commit be7a766cb2
8 changed files with 31 additions and 24 deletions

View File

@@ -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"

View File

@@ -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
}
}