mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-06-08 10:13:12 +00:00
25a5f37d3d
Implements Phases 02 (partial) and 03 of the go-port-cloud-run plan. Introduces module framework with per-module KV prefix isolation, health check endpoint, request timeout protection, and comprehensive test coverage. Cloud Run deployment deferred to Phase 01. Security hardening: constant-time secret comparison, cron auth bridge, and secrets stripped from dependency environment exports. Includes Dockerfile, GitHub CI workflow (vet + race + build), and integration tests for module lifecycle.
37 lines
838 B
Go
37 lines
838 B
Go
package modules
|
|
|
|
import (
|
|
"fmt"
|
|
"regexp"
|
|
)
|
|
|
|
var commandNameRe = regexp.MustCompile(`^[a-z0-9_]{1,32}$`)
|
|
|
|
func validateCommand(c Command) error {
|
|
if !commandNameRe.MatchString(c.Name) {
|
|
return fmt.Errorf("command name %q must match %s", c.Name, commandNameRe)
|
|
}
|
|
switch c.Visibility {
|
|
case VisibilityPublic, VisibilityProtected, VisibilityPrivate:
|
|
default:
|
|
return fmt.Errorf("command %q: unknown visibility %d", c.Name, c.Visibility)
|
|
}
|
|
if c.Description == "" {
|
|
return fmt.Errorf("command %q: description is required", c.Name)
|
|
}
|
|
if c.Handler == nil {
|
|
return fmt.Errorf("command %q: handler is nil", c.Name)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func validateCron(c Cron) error {
|
|
if c.Name == "" {
|
|
return fmt.Errorf("cron: name is required")
|
|
}
|
|
if c.Handler == nil {
|
|
return fmt.Errorf("cron %q: handler is nil", c.Name)
|
|
}
|
|
return nil
|
|
}
|