Files
HackBrowserData/internal/category/category.go
T
Roger 3e9150249c refactor: rename core types and spell out every name (#677)
Def, Request, DirID, and Source said too little, and short variables and doc comments that skip their name hid intent.
varnamelen and staticcheck ST1020-22 now keep both from coming back.
2026-11-02 11:06:05 +08:00

67 lines
1.3 KiB
Go

package category
import "fmt"
// Category 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 gives the -c values and the output file names, so its values 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, dataCategory := range all {
names[i] = dataCategory.String()
}
return names
}
func Parse(value string) (Category, error) {
for _, dataCategory := range All() {
if dataCategory.String() == value {
return dataCategory, nil
}
}
return 0, fmt.Errorf("unknown category: %q", value)
}