Added websocket hub for handling websocket clients, with a wsserve command
which runs a plain TCP server for receiving websocket hub clients, with server config, CSRF and rate limit middleware. - internal/websocket: Hub pushing messages to WebSocket clients (ServeHTTP, example.com/ws upgrade with optional CSRF check) and plain TCP clients (ServeTCP, newline-delimited JSON envelopes); ping/pong keepalive, per-client message rate limit, slow consumer handling, graceful Shutdown, debug logging of messages sent and received - internal/websocket/tcpserver: standalone TCP server for a hub, with accept back-off, a per-IP connection limit (server.websocket.connection_limit) and graceful shutdown - internal/cli/wsserve: `wsserve` command running the TCP server, with --listen/--host/--port overrides - internal/middleware: keyed token bucket rate limiter, real client IP from trusted proxies - internal/httpx: RFC 9457 problem responses, request IDs in context - internal/config: server section (host, port, shutdown timeout, rate limiter idle TTL, websocket); util.ByteSize settings (e.g. "32KiB"); lists of sections as single keys; empty lists stored as nil; isExplicitlySet for printLoadedConfig; JobSearchConfigSource renamed to JSCSourcesSource; TestSections checks every section's methods - internal/util: ByteSize, parsed and formatted with go-humanize
This commit is contained in:
1 parent
803a8929e6
commit
c9f42b62ad
42 files changed
+3619
-57
No files matched your search
@@ -24,9 +24,10 @@ const EtcConfigPath string = "/etc/job-search"
|
||||
// JobSearchConfig is the application's whole configuration, one field per
|
||||
// section. Each field's cfg tag must match the section's JSCK* constant.
|
||||
type JobSearchConfig struct {
|
||||
Database JSCDatabase `cfg:"database"`
|
||||
Logging JSCLogging `cfg:"logging"`
|
||||
Sources JSCSources `cfg:"sources"`
|
||||
Database JSCDatabase `cfg:"database"`
|
||||
Logging JSCLogging `cfg:"logging"`
|
||||
Server JSCServer `cfg:"server"`
|
||||
Sources JSCSources `cfg:"sources"`
|
||||
}
|
||||
|
||||
// LoadDefaultConfig sets Viper's defaults from the configuration's default
|
||||
@@ -88,6 +89,24 @@ func viperValue(key string, kind reflect.Kind) (value any, ok bool) {
|
||||
return viper.GetInt(key), true
|
||||
case reflect.Bool:
|
||||
return viper.GetBool(key), true
|
||||
case reflect.Slice:
|
||||
// A string, e.g. from an environment variable, is passed on for
|
||||
// SetValue to split on commas; GetStringSlice would split it on
|
||||
// spaces. A list of objects (a list of sections) is passed on as it
|
||||
// is, as GetStringSlice would flatten it.
|
||||
switch v := viper.Get(key).(type) {
|
||||
case string:
|
||||
return v, true
|
||||
case []map[string]any: // as LoadToViper sets it
|
||||
return v, true
|
||||
case []any:
|
||||
if len(v) > 0 {
|
||||
if _, ok := v[0].(map[string]any); ok {
|
||||
return v, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return viper.GetStringSlice(key), true
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user