Weighs the soul of incoming HTTP requests to stop AI crawlers
1package store
2
3import (
4 "context"
5 "encoding/json"
6 "sort"
7 "sync"
8)
9
10var (
11 registry map[string]Factory = map[string]Factory{}
12 regLock sync.RWMutex
13)
14
15type Factory interface {
16 Build(ctx context.Context, config json.RawMessage) (Interface, error)
17 Valid(config json.RawMessage) error
18}
19
20func Register(name string, impl Factory) {
21 regLock.Lock()
22 defer regLock.Unlock()
23
24 registry[name] = impl
25}
26
27func Get(name string) (Factory, bool) {
28 regLock.RLock()
29 defer regLock.RUnlock()
30 result, ok := registry[name]
31 return result, ok
32}
33
34func Methods() []string {
35 regLock.RLock()
36 defer regLock.RUnlock()
37 var result []string
38 for method := range registry {
39 result = append(result, method)
40 }
41 sort.Strings(result)
42 return result
43}