You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This came from https://github.com/ldemailly/go-flagz, a fork of the code originally on https://github.com/mwitkow/go-flagz and https://github.com/improbable-eng/go-flagz with initial changes to get the go modules to work, reduce boiler plate needed for configmap watcher, avoid panic when there is extra whitespace, make the watcher work with regular files and relative paths and switched to standard golang flags.
4
-
And now further changes, simplification, etc... as part of fortio.
5
-
And then moved to a toplevel package in the fortio org.
6
-
7
-
Thanks to [@mwitkow](https://github.com/mwitkow) for having created this originally.
Dynamic, thread-safe `flag` variables that can be modified at runtime through files, URL endpoint,
14
7
or [Kubernetes](http://kubernetes.io) configmap changes.
15
8
16
-
For a similar project for JVM languages (Java, scala) see [java-flagz](https://github.com/mwitkow/java-flagz)
17
-
18
-
Now rewritten and simplified and extended thanks to Go 1.18 generics (use versions prior to 1.33 if you want to use the older per type implementation)
9
+
See History section below.
19
10
20
11
## This sounds crazy. Why?
21
12
@@ -32,7 +23,8 @@ All of this can be done simultaneously across a whole shard of your services.
32
23
## Features
33
24
34
25
* compatible with standard go `flag` package
35
-
* dynamic `flag` that are thread-safe and efficient, now also `Dyn[T]` generic:
26
+
* dynamic `flag` that are thread-safe and efficient
27
+
-`Dyn[T]` generic, or
36
28
-`DynBool`
37
29
-`DynInt64`
38
30
-`DynFloat64`
@@ -55,7 +47,6 @@ Here's a teaser of the debug endpoint:
55
47
56
48
Declare a single `flag.FlagSet` in some public package (e.g. `common.SharedFlagSet`) that you'll use throughout your server or stick to `flag.CommandLine` default flagset for your binary.
57
49
58
-
59
50
### Dynamic JSON flag with a validator and notifier
All access to `featuresFlag`, which is a `[]string` flag, is synchronized across go-routines using `atomic` pointer swaps.
82
+
91
83
## Library versus caller style
84
+
NEW:
92
85
93
86
```golang
94
87
// In the library "libfoo" package
95
-
varMyConfig = dflag.New("default value", "explanation of what that is for").WithValidator(MyValidator)
88
+
varMyConfig = dflag.New("default value", "explanation of what that is for").WithValidator(myValidator)
96
89
// In the caller/users, bind to an actual flag:
97
90
dflag.Flag("foocfg", libfoo.MyConfig) // defines -foocfg flag
98
91
```
99
92
100
93
## Complete example
101
94
102
-
See a [http server](examples/server_kube) complete example.
95
+
See a [http server](examples/server_kube) complete example or the [fortio.org/scli](https://github.com/fortio/scli#scli) package for easy reuse/configuration.
96
+
97
+
## History
98
+
99
+
This came from https://github.com/ldemailly/go-flagz, a fork of the code originally on https://github.com/mwitkow/go-flagz and https://github.com/improbable-eng/go-flagz with initial changes to get the go modules to work, reduce boiler plate needed for configmap watcher, avoid panic when there is extra whitespace, make the watcher work with regular files and relative paths and switched to standard golang flags.
100
+
101
+
And further changes, simplification, etc... as part of fortio.
102
+
103
+
Including rewrite and simplifications taking advantage of go 1.18 and newer generics support (use versions in fortio prior to 1.33 if you want to use the older per type implementation)
104
+
105
+
And now moved to a toplevel package in the fortio org.
106
+
107
+
For a similar project for JVM languages (Java, scala) see [java-flagz](https://github.com/mwitkow/java-flagz)
108
+
109
+
Thanks to [@mwitkow](https://github.com/mwitkow) for having created this originally.
103
110
104
-
# Status
111
+
##Status
105
112
106
113
This code is *production* quality. It's been running happily in production in its earlier incarnation at Improbable for years and now everywhere fortio runs.
0 commit comments