mirror of
https://github.com/tiennm99/openai-status-bot.git
synced 2026-07-14 11:08:46 +00:00
546e6fcde2
Swap the Redis datastore for MongoDB via mongo-driver v2. New internal/mongostore mirrors the old redisstore type/constant names so consumers change only the import qualifier; document model collapses the multi-key subscriber/settings and per-event delivery sets into single-doc operations and a TTL-indexed delivery collection. Config now requires MONGODB_URI (Atlas) with MONGODB_DATABASE selecting dev vs prod on one cluster; REDIS_URL removed. Compose files run bot-only against Atlas. Default tests stay Docker-free (poller/bot use fakes, mongostore unit tests are pure-logic); a gated //go:build integration suite covers the real backend via testcontainers.
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package mongostore
|
|
|
|
import "strings"
|
|
|
|
func normalizeTypes(types []string) []string {
|
|
normalized := make([]string, 0, len(types))
|
|
for _, value := range types {
|
|
switch strings.ToLower(strings.TrimSpace(value)) {
|
|
case SubscriptionTypeIncident:
|
|
if !containsFold(normalized, SubscriptionTypeIncident) {
|
|
normalized = append(normalized, SubscriptionTypeIncident)
|
|
}
|
|
case SubscriptionTypeComponent:
|
|
if !containsFold(normalized, SubscriptionTypeComponent) {
|
|
normalized = append(normalized, SubscriptionTypeComponent)
|
|
}
|
|
}
|
|
}
|
|
if len(normalized) == 0 {
|
|
return DefaultSubscriptionTypes()
|
|
}
|
|
return normalized
|
|
}
|
|
|
|
func normalizeComponents(components []string) []string {
|
|
normalized := make([]string, 0, len(components))
|
|
for _, component := range components {
|
|
component = strings.TrimSpace(component)
|
|
if component == "" || containsFold(normalized, component) {
|
|
continue
|
|
}
|
|
normalized = append(normalized, component)
|
|
}
|
|
return normalized
|
|
}
|
|
|
|
func containsFold(values []string, target string) bool {
|
|
for _, value := range values {
|
|
if strings.EqualFold(value, target) {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|