mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 01:08:31 +02:00
add help messages to rules, updat url validation
This commit is contained in:
35
internal/route/rules/help.go
Normal file
35
internal/route/rules/help.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package rules
|
||||
|
||||
import "strings"
|
||||
|
||||
type Help struct {
|
||||
command string
|
||||
args map[string]string // args[arg] -> description
|
||||
}
|
||||
|
||||
/*
|
||||
Generate help string, e.g.
|
||||
|
||||
rewrite <from> <to>
|
||||
from: the path to rewrite, must start with /
|
||||
to: the path to rewrite to, must start with /
|
||||
*/
|
||||
func (h *Help) String() string {
|
||||
var sb strings.Builder
|
||||
sb.WriteString(h.command)
|
||||
sb.WriteString(" ")
|
||||
for arg := range h.args {
|
||||
sb.WriteRune('<')
|
||||
sb.WriteString(arg)
|
||||
sb.WriteString("> ")
|
||||
}
|
||||
sb.WriteRune('\n')
|
||||
for arg, desc := range h.args {
|
||||
sb.WriteRune('\t')
|
||||
sb.WriteString(arg)
|
||||
sb.WriteString(": ")
|
||||
sb.WriteString(desc)
|
||||
sb.WriteRune('\n')
|
||||
}
|
||||
return sb.String()
|
||||
}
|
||||
Reference in New Issue
Block a user