Skip to content

Commit

Permalink
Merge pull request #1478 from shirou/feature/add_doc_about_ctx
Browse files Browse the repository at this point in the history
add(README): add passing context value document
  • Loading branch information
shirou authored Jun 4, 2023
2 parents 5a20eac + 341d501 commit 1754b81
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 1754b81

Please sign in to comment.