41 lines
3.3 KiB
Go
41 lines
3.3 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// RouteSurface describes one externally visible route explicitly owned by the
|
|
// Go modular monolith. It is kept source-independent so contract tests can
|
|
// compare it with the checked-in public HTTP contract.
|
|
type RouteSurface struct {
|
|
Method string `json:"method"`
|
|
Path string `json:"path"`
|
|
}
|
|
|
|
var goRouteSurface = []RouteSurface{
|
|
{"DELETE", "/api/admin/accounts"}, {"GET", "/api/admin/accounts"}, {"PATCH", "/api/admin/accounts"}, {"POST", "/api/admin/accounts"}, {"PUT", "/api/admin/accounts"}, {"POST", "/api/admin/accounts/groups"}, {"POST", "/api/admin/accounts/password"}, {"GET", "/api/admin/billing"}, {"PATCH", "/api/admin/billing/account"}, {"POST", "/api/admin/billing/adjustments"}, {"GET", "/api/admin/billing/prices"}, {"PATCH", "/api/admin/billing/prices/{id}"}, {"DELETE", "/api/admin/organizations"}, {"GET", "/api/admin/organizations"}, {"PATCH", "/api/admin/organizations"}, {"POST", "/api/admin/organizations"}, {"GET", "/api/admin/usage"},
|
|
{"GET", "/api/assets"}, {"POST", "/api/assets"}, {"POST", "/api/assets/upload"}, {"DELETE", "/api/assets/{id}"}, {"GET", "/api/assets/{id}/download"},
|
|
{"GET", "/api/auth/callback"}, {"GET", "/api/auth/captcha"}, {"GET", "/api/auth/login"}, {"GET", "/api/auth/logout"}, {"POST", "/api/auth/logout"}, {"GET", "/api/auth/me"}, {"POST", "/api/auth/password"}, {"POST", "/api/auth/password/change"},
|
|
{"GET", "/api/billing"}, {"POST", "/api/billing/quote"}, {"GET", "/api/generations/image"}, {"POST", "/api/generations/image"}, {"DELETE", "/api/generations/image/{id}"}, {"GET", "/api/generations/image/{id}"}, {"POST", "/api/generations/image/{id}/retry"}, {"GET", "/api/generations/video"}, {"POST", "/api/generations/video"}, {"DELETE", "/api/generations/video/{id}"}, {"GET", "/api/generations/video/{id}"},
|
|
{"GET", "/api/health"}, {"GET", "/api/image-templates"}, {"POST", "/api/image-templates"}, {"DELETE", "/api/image-templates/{id}"}, {"PATCH", "/api/image-templates/{id}"}, {"POST", "/api/internal/worker/tick"}, {"GET", "/api/layer-compositions/{id}"}, {"PUT", "/api/layer-compositions/{id}"}, {"DELETE", "/api/logs"}, {"GET", "/api/logs"}, {"POST", "/api/prompt/assemble"}, {"GET", "/api/ready"}, {"GET", "/api/settings"}, {"POST", "/api/settings"}, {"GET", "/api/usage"},
|
|
{"GET", "/api/v1/assets"}, {"POST", "/api/v1/assets"}, {"GET", "/api/v1/assets/{id}"}, {"GET", "/api/v1/assets/{id}/download"}, {"GET", "/api/v1/capabilities"}, {"GET", "/api/v1/jobs"}, {"POST", "/api/v1/jobs"}, {"GET", "/api/v1/jobs/{id}"}, {"POST", "/api/v1/jobs/{id}/cancel"}, {"GET", "/api/v1/openapi.json"}, {"GET", "/generated-results/{path...}"}, {"GET", "/uploads/{path...}"},
|
|
}
|
|
|
|
func GoRouteSurface() []RouteSurface { return append([]RouteSurface(nil), goRouteSurface...) }
|
|
|
|
func MatchSurfacePath(pattern, path string) bool {
|
|
if strings.HasSuffix(pattern, "/{path...}") {
|
|
prefix := strings.TrimSuffix(pattern, "{path...}")
|
|
return strings.HasPrefix(path, prefix) && strings.TrimPrefix(path, prefix) != ""
|
|
}
|
|
if strings.Contains(pattern, "{id}") {
|
|
prefix, suffix, _ := strings.Cut(pattern, "{id}")
|
|
if !strings.HasPrefix(path, prefix) || !strings.HasSuffix(path, suffix) {
|
|
return false
|
|
}
|
|
value := strings.TrimSuffix(strings.TrimPrefix(path, prefix), suffix)
|
|
return value != "" && !strings.Contains(value, "/")
|
|
}
|
|
return pattern == path
|
|
}
|