Documentation
¶
Overview ¶
Package urlcat is the admin-managed URL-category engine: named categories with lowercase host-set indexing for O(labels) membership checks during policy evaluation, JSON file persistence, and the built-in + embedded-SaaS default seed list. Extracted from package main's policy.go per ADR-0002 (policy.go decomposition Phase A).
package main keeps the surfaces: the `catStore` singleton, the TWO-TIER category resolution (matchCategory / lookupHostCategory compose this store with the community BadgerDB feed), the API handlers, cluster sync, and config-version rollback — all through aliases.
Index ¶
- type Category
- type Entry
- type Store
- func (s *Store) AddHost(category, host string) error
- func (s *Store) All() []Entry
- func (s *Store) Delete(name string) error
- func (s *Store) GetByName(name string) *Entry
- func (s *Store) Load(path string) error
- func (s *Store) LookupHost(host string) (category, matchedBy string, ok bool)
- func (s *Store) MatchesHost(cat Category, host string) bool
- func (s *Store) Path() string
- func (s *Store) RemoveHost(category, host string) error
- func (s *Store) ReplaceAll(cats []Entry)
- func (s *Store) Save()
- func (s *Store) Set(name string, hosts []string, builtIn bool) error
- func (s *Store) SetPathForTest(path string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Entry ¶
type Entry struct {
Name string `json:"name"`
Hosts []string `json:"hosts"`
BuiltIn bool `json:"builtIn"` // seeded from built-in defaults; editable by admin
}
Entry is one named URL category with its list of host patterns.
func DefaultEntries ¶
func DefaultEntries() []*Entry
DefaultEntries returns the built-in hardcoded categories merged with the embedded SaaS category seed list.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store manages URL categories with thread-safe, file-backed persistence. index maps lowercase(category-name) → set of lowercase host strings for O(1) host membership checks during policy evaluation.
func (*Store) GetByName ¶
GetByName finds a category by name (case-insensitive). Returns the live entry pointer (callers treat it as read-only outside the store's lock — pre-extraction contract preserved).
func (*Store) Load ¶
Load reads categories from a JSON file. If the file does not exist the built-in defaults are seeded and written to disk.
func (*Store) LookupHost ¶
LookupHost resolves a hostname to its category by scanning entries (exact + suffix match), returning the original-case category name and the pattern that matched. Deliberately scans the entry lists — not the lowercase index — so matchedBy reports the admin's configured pattern verbatim (admin URL-lookup API contract).
func (*Store) MatchesHost ¶
MatchesHost checks whether host belongs to the named URL category. Uses the pre-built index for O(labels) lookup instead of O(N×M) iteration.
func (*Store) RemoveHost ¶
RemoveHost deletes a host from the named category.
func (*Store) ReplaceAll ¶
ReplaceAll atomically replaces all categories (used by cluster config sync).
func (*Store) SetPathForTest ¶
SetPathForTest points persistence at path without loading (Load on a missing file would seed the defaults; tests often want an EMPTY store that saves to a temp location).