Just wondering if it is possible to store key/value pairs in an external config.json file and be able to access those values to use within an HTTP header?
For example, if i have
{
“MyNamespace”:["/mynamespace"]
}
in an external file (which i can access now) and would like to use the MyNamespace value and set it in
If your JSON config file holds the response header kv pairs in something like:
{
..,
"responseheaders":{"Cache-Control":"no-store"},
...
}
that is read into a configuration struct with the following member:
type Context struct {
...
ResponseHeaders map[string]string
...
}
var Ctx Context
Then you can load the response header like this:
func myFileServer(w http.ResponseWriter, r *http.Request) {
...
// load Header k:v pairs
for k, v := range Ctx.ResponseHeaders {
w.Header().Set(k, v)
}
...
}