github.com/anycable/anycable-go@v1.5.1/config/config.go (about) 1 package config 2 3 import ( 4 "github.com/anycable/anycable-go/broadcast" 5 "github.com/anycable/anycable-go/broker" 6 "github.com/anycable/anycable-go/enats" 7 "github.com/anycable/anycable-go/identity" 8 "github.com/anycable/anycable-go/metrics" 9 nconfig "github.com/anycable/anycable-go/nats" 10 "github.com/anycable/anycable-go/node" 11 rconfig "github.com/anycable/anycable-go/redis" 12 "github.com/anycable/anycable-go/rpc" 13 "github.com/anycable/anycable-go/server" 14 "github.com/anycable/anycable-go/sse" 15 "github.com/anycable/anycable-go/streams" 16 "github.com/anycable/anycable-go/ws" 17 18 nanoid "github.com/matoous/go-nanoid" 19 ) 20 21 // Config contains main application configuration 22 type Config struct { 23 ID string 24 Secret string 25 BroadcastKey string 26 SkipAuth bool 27 App node.Config 28 RPC rpc.Config 29 BrokerAdapter string 30 Broker broker.Config 31 Redis rconfig.RedisConfig 32 HTTPBroadcast broadcast.HTTPConfig 33 NATS nconfig.NATSConfig 34 Host string 35 Port int 36 MaxConn int 37 BroadcastAdapter string 38 PubSubAdapter string 39 Path []string 40 HealthPath string 41 Headers []string 42 Cookies []string 43 SSL server.SSLConfig 44 WS ws.Config 45 MaxMessageSize int64 46 DisconnectorDisabled bool 47 DisconnectQueue node.DisconnectQueueConfig 48 LogLevel string 49 LogFormat string 50 Debug bool 51 Metrics metrics.Config 52 JWT identity.JWTConfig 53 EmbedNats bool 54 EmbeddedNats enats.Config 55 SSE sse.Config 56 Streams streams.Config 57 UserPresets []string 58 } 59 60 // NewConfig returns a new empty config 61 func NewConfig() Config { 62 id, _ := nanoid.Nanoid(6) 63 64 config := Config{ 65 ID: id, 66 Host: "localhost", 67 Port: 8080, 68 Path: []string{"/cable"}, 69 HealthPath: "/health", 70 BroadcastAdapter: "http,redis", 71 Broker: broker.NewConfig(), 72 Headers: []string{"cookie"}, 73 LogLevel: "info", 74 LogFormat: "text", 75 App: node.NewConfig(), 76 SSL: server.NewSSLConfig(), 77 WS: ws.NewConfig(), 78 Metrics: metrics.NewConfig(), 79 RPC: rpc.NewConfig(), 80 Redis: rconfig.NewRedisConfig(), 81 HTTPBroadcast: broadcast.NewHTTPConfig(), 82 NATS: nconfig.NewNATSConfig(), 83 DisconnectQueue: node.NewDisconnectQueueConfig(), 84 JWT: identity.NewJWTConfig(""), 85 EmbeddedNats: enats.NewConfig(), 86 SSE: sse.NewConfig(), 87 Streams: streams.NewConfig(), 88 } 89 90 return config 91 } 92 93 func (c Config) IsPublic() bool { 94 return c.SkipAuth && c.Streams.Public 95 }