Files
HackBrowserData/internal/category/category.go
T
Roger 4e98ba7884 fix: report unreadable sources and tidy the pipeline (#675)
A Stat error other than not-exist was reported as absent, and the --zip archive was readable by other users.
The rest is review follow-up: export no longer prints, one runner type, shared name helpers, a trimmed log API.
2026-11-01 23:42:13 +08:00

67 lines
1.2 KiB
Go

package category
import "fmt"
// Numbering starts at 1, so the zero Category means "none".
type Category int
const (
Password Category = iota + 1
Cookie
Bookmark
History
Download
CreditCard
Extension
LocalStorage
SessionStorage
)
// String's values are the -c values and the output file names, so they cannot change.
func (c Category) String() string {
switch c {
case Password:
return "password"
case Cookie:
return "cookie"
case Bookmark:
return "bookmark"
case History:
return "history"
case Download:
return "download"
case CreditCard:
return "creditcard"
case Extension:
return "extension"
case LocalStorage:
return "localstorage"
case SessionStorage:
return "sessionstorage"
default:
return "unknown"
}
}
func All() []Category {
return []Category{Password, Cookie, Bookmark, History, Download, CreditCard, Extension, LocalStorage, SessionStorage}
}
func Names() []string {
all := All()
names := make([]string, len(all))
for i, c := range all {
names[i] = c.String()
}
return names
}
func Parse(s string) (Category, error) {
for _, c := range All() {
if c.String() == s {
return c, nil
}
}
return 0, fmt.Errorf("unknown category: %q", s)
}