Skip to content

Commit

Permalink
add(README): add passing context value document
Browse files Browse the repository at this point in the history
which is introduced by #1439.
  • Loading branch information
shirou committed Jun 4, 2023
1 parent 5a20eac commit 341d501
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ environment variable.
You can set an alternative location to `/proc/N/mountinfo` by setting the
`HOST_PROC_MOUNTINFO` environment variable.

### Adding settings using `context` (from v3.23.6)

As of v3.23.6, it is now possible to pass a path location using `context`: import `"github.com/shirou/gopsutil/v3/common"` and pass a context with `common.EnvMap` set to `common.EnvKey`, and the location will be used within each function.

```
ctx := context.WithValue(context.Background(),
common.EnvKey, common.EnvMap{common.HostProcEnvKey: "/myproc"},
)
v, err := mem.VirtualMemoryWithContext(ctx)
```

First priority is given to the value set in `context`, then the value from the environment variable, and finally the default location.

## Documentation

See https://pkg.go.dev/github.com/shirou/gopsutil/v3 or https://godocs.io/github.com/shirou/gopsutil/v3
Expand Down

0 comments on commit 341d501

Please sign in to comment.