Providers
Flux providers live in pkg/ with isolated dependencies. Each implements the Watcher interface for a specific backend.
Installation
Install only the providers you need:
go get github.com/zoobz-io/flux/file
go get github.com/zoobz-io/flux/redis
go get github.com/zoobz-io/flux/consul
# etc.
Provider Overview
| Provider | Backend | Watch Mechanism | Use Case |
|---|---|---|---|
pkg/file | Local FS | fsnotify | Local config files |
pkg/redis | Redis | Keyspace notifications | Shared config, feature flags |
pkg/consul | Consul KV | Blocking queries | Service configuration |
pkg/etcd | etcd | Watch API | Distributed config |
pkg/nats | NATS JetStream | KV Watch | Cloud-native messaging |
pkg/kubernetes | ConfigMap/Secret | Watch API | K8s-native apps |
pkg/zookeeper | ZooKeeper | Node watch | Legacy systems |
pkg/firestore | Firestore | Realtime listeners | GCP applications |
File
Watch local filesystem files using fsnotify.
import "github.com/zoobz-io/flux/file"
capacitor := flux.New[Config](
file.New("/etc/myapp/config.json"),
callback,
)
Best for: Local development, single-instance deployments, config files managed by CM tools.
Redis
Watch Redis keys using keyspace notifications.
import (
"github.com/redis/go-redis/v9"
fluxredis "github.com/zoobz-io/flux/redis"
)
client := redis.NewClient(&redis.Options{Addr: "localhost:6379"})
capacitor := flux.New[Config](
fluxredis.New(client, "myapp:config"),
callback,
)
Requires keyspace notifications enabled:
redis-cli CONFIG SET notify-keyspace-events KEA
Best for: Feature flags, shared configuration across instances.
Consul
Watch Consul KV using blocking queries.
import (
"github.com/hashicorp/consul/api"
fluxconsul "github.com/zoobz-io/flux/consul"
)
client, _ := api.NewClient(api.DefaultConfig())
capacitor := flux.New[Config](
fluxconsul.New(client, "myapp/config"),
callback,
)
Best for: HashiCorp ecosystem, service mesh configurations.
etcd
Watch etcd keys using the native Watch API.
import (
clientv3 "go.etcd.io/etcd/client/v3"
fluxetcd "github.com/zoobz-io/flux/etcd"
)
client, _ := clientv3.New(clientv3.Config{
Endpoints: []string{"localhost:2379"},
})
capacitor := flux.New[Config](
fluxetcd.New(client, "/myapp/config"),
callback,
)
Best for: Kubernetes ecosystem, distributed systems requiring strong consistency.
NATS
Watch NATS JetStream KV buckets.
import (
"github.com/nats-io/nats.go"
"github.com/nats-io/nats.go/jetstream"
fluxnats "github.com/zoobz-io/flux/nats"
)
nc, _ := nats.Connect("nats://localhost:4222")
js, _ := jetstream.New(nc)
kv, _ := js.KeyValue(ctx, "config")
capacitor := flux.New[Config](
fluxnats.New(kv, "myapp"),
callback,
)
Best for: Cloud-native apps, microservices using NATS for messaging.
Kubernetes
Watch ConfigMaps or Secrets.
import (
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
fluxk8s "github.com/zoobz-io/flux/kubernetes"
)
config, _ := rest.InClusterConfig()
client, _ := kubernetes.NewForConfig(config)
// ConfigMap (default)
capacitor := flux.New[Config](
fluxk8s.New(client, "default", "myapp-config", "config.json"),
callback,
)
// Secret
capacitor := flux.New[Config](
fluxk8s.New(client, "default", "myapp-secret", "config.json",
fluxk8s.WithResourceType(fluxk8s.Secret),
),
callback,
)
Best for: Kubernetes-native applications, GitOps workflows.
ZooKeeper
Watch ZooKeeper nodes.
import (
"github.com/go-zookeeper/zk"
fluxzk "github.com/zoobz-io/flux/zookeeper"
)
conn, _, _ := zk.Connect([]string{"localhost:2181"}, 5*time.Second)
capacitor := flux.New[Config](
fluxzk.New(conn, "/config/myapp"),
callback,
)
Best for: Legacy systems, Kafka ecosystem, existing ZK infrastructure.
Firestore
Watch Firestore documents using realtime listeners.
import (
"cloud.google.com/go/firestore"
fluxfs "github.com/zoobz-io/flux/firestore"
)
client, _ := firestore.NewClient(ctx, "my-project")
capacitor := flux.New[Config](
fluxfs.New(client, "config", "myapp"),
callback,
)
Document structure: By default expects a data field containing JSON:
{"data": "{\"port\": 8080}"}
Use helper functions:
fluxfs.CreateDocument(ctx, client, "config", "myapp", []byte(`{"port": 8080}`))
fluxfs.UpdateDocument(ctx, client, "config", "myapp", []byte(`{"port": 9090}`))
Best for: GCP applications, serverless deployments on Cloud Run/Functions.
Choosing a Provider
| Requirement | Recommended |
|---|---|
| Simple, single instance | file |
| Shared across instances | redis, consul, etcd |
| Kubernetes-native | kubernetes |
| GCP/Firebase | firestore |
| NATS messaging | nats |
| Existing ZK infrastructure | zookeeper |
Next Steps
- Custom Watcher - Build your own provider
- Multi-Source - Combine multiple providers