Skip to content

Commit

Permalink
move history to its own section of the README
Browse files Browse the repository at this point in the history
  • Loading branch information
ldemailly committed Feb 19, 2023
1 parent 93ac7e0 commit f4d620f
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
[![codecov](https://codecov.io/github/fortio/dflag/branch/main/graph/badge.svg?token=LONYZDFQ7C)](https://codecov.io/github/fortio/dflag)

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.
And now further changes, simplification, etc... as part of fortio.
And then moved to a toplevel package in the fortio org.

Thanks to [@mwitkow](https://github.com/mwitkow) for having created this originally.

# Fortio Dynamic Flags (was Go FlagZ)

[![Apache 2.0 License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)

# Fortio Dynamic Flags

Dynamic, thread-safe `flag` variables that can be modified at runtime through files, URL endpoint,
or [Kubernetes](http://kubernetes.io) configmap changes.

For a similar project for JVM languages (Java, scala) see [java-flagz](https://github.com/mwitkow/java-flagz)

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)
See History section below.

## This sounds crazy. Why?

Expand All @@ -32,7 +23,8 @@ All of this can be done simultaneously across a whole shard of your services.
## Features

* compatible with standard go `flag` package
* dynamic `flag` that are thread-safe and efficient, now also `Dyn[T]` generic:
* dynamic `flag` that are thread-safe and efficient
- `Dyn[T]` generic, or
- `DynBool`
- `DynInt64`
- `DynFloat64`
Expand All @@ -55,7 +47,6 @@ Here's a teaser of the debug endpoint:

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.


### Dynamic JSON flag with a validator and notifier

```go
Expand Down Expand Up @@ -88,20 +79,36 @@ func MyHandler(resp http.ResponseWriter, req *http.Request) {
```

All access to `featuresFlag`, which is a `[]string` flag, is synchronized across go-routines using `atomic` pointer swaps.

## Library versus caller style
NEW:

```golang
// In the library "libfoo" package
var MyConfig = dflag.New("default value", "explanation of what that is for").WithValidator(MyValidator)
var MyConfig = dflag.New("default value", "explanation of what that is for").WithValidator(myValidator)
// In the caller/users, bind to an actual flag:
dflag.Flag("foocfg", libfoo.MyConfig) // defines -foocfg flag
```

## Complete example

See a [http server](examples/server_kube) complete example.
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.

## History

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.

And further changes, simplification, etc... as part of fortio.

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)

And now moved to a toplevel package in the fortio org.

For a similar project for JVM languages (Java, scala) see [java-flagz](https://github.com/mwitkow/java-flagz)

Thanks to [@mwitkow](https://github.com/mwitkow) for having created this originally.

# Status
## Status

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.

Expand Down

0 comments on commit f4d620f

Please sign in to comment.