Improve context package
You shouldn't have to import both: github.com/docker/distribution/context golang.org/x/net/context just to use the distribution tools and implement the distribution interfaces. By pulling the Context interface from golang.org/x/net/context into the context package within the distribution project, you no longer have to import both packages. Note: You do not have to change anything anywhere else yet! All current uses of both packages together will still work correctly because the Context interface from either package is identical. I've also made some other minor changes: - Added a RemoteIP function. It's like RemoteAddr but discards the port suffix - Added `.String()` to the response duration context value so that JSON log formatting shows human-parseable duration and not just number of nano-seconds - Added WithMapContext(...) to the context package. This is a useful function so I pulled it out of the main.go in cmd/registry so that it can be used elsewhere. Docker-DCO-1.1-Signed-off-by: Josh Hawn <josh.hawn@docker.com> (github: jlhawn)
This commit is contained in:
parent
5052dc692f
commit
731e0b0066
9 changed files with 97 additions and 63 deletions
|
@ -17,11 +17,11 @@ func Test(t *testing.T) { TestingT(t) }
|
|||
var configStruct = Configuration{
|
||||
Version: "0.1",
|
||||
Log: struct {
|
||||
Level Loglevel `yaml:"level"`
|
||||
Formatter string `yaml:"formatter"`
|
||||
Fields map[string]string `yaml:"fields"`
|
||||
Level Loglevel `yaml:"level"`
|
||||
Formatter string `yaml:"formatter"`
|
||||
Fields map[string]interface{} `yaml:"fields"`
|
||||
}{
|
||||
Fields: map[string]string{"environment": "test"},
|
||||
Fields: map[string]interface{}{"environment": "test"},
|
||||
},
|
||||
Loglevel: "info",
|
||||
Storage: Storage{
|
||||
|
@ -340,7 +340,7 @@ func copyConfig(config Configuration) *Configuration {
|
|||
configCopy.Version = MajorMinorVersion(config.Version.Major(), config.Version.Minor())
|
||||
configCopy.Loglevel = config.Loglevel
|
||||
configCopy.Log = config.Log
|
||||
configCopy.Log.Fields = make(map[string]string, len(config.Log.Fields))
|
||||
configCopy.Log.Fields = make(map[string]interface{}, len(config.Log.Fields))
|
||||
for k, v := range config.Log.Fields {
|
||||
configCopy.Log.Fields[k] = v
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue