From 341d501dce88f8454fc08bba91d79c1a7a8ad19d Mon Sep 17 00:00:00 2001 From: shirou Date: Sun, 4 Jun 2023 08:11:13 +0000 Subject: [PATCH] add(README): add passing context value document which is introduced by #1439. --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index d1a408a8a..bc521f4ea 100644 --- a/README.md +++ b/README.md @@ -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