Files
tiennm99 25a5f37d3d feat(server,modules): bootstrap server and module framework
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.
2026-05-08 23:27:12 +07:00

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
}