-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #763 from devlights/add-os-setenv-example
- Loading branch information
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package osop | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/devlights/gomy/output" | ||
) | ||
|
||
// Setenv は、os.Setenv() のサンプルです。 | ||
// | ||
// 既に存在する環境変数に対して os.Setenv() した場合は | ||
// そのプロセス内で値が上書きされる。 | ||
// | ||
// # REFERENCES | ||
// | ||
// - https://pkg.go.dev/[email protected]#Setenv | ||
func Setenv() error { | ||
var err error | ||
|
||
err = os.Setenv("MYENV1", "HELLOWORLD") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
output.Stdoutl("[MYENV1]", os.Getenv("MYENV1")) | ||
|
||
err = os.Setenv("HOSTNAME", "HELLOWORLD") | ||
if err != nil { | ||
return err | ||
} | ||
|
||
output.Stdoutl("[HOSTNAME]", os.Getenv("HOSTNAME")) | ||
|
||
return nil | ||
|
||
/* | ||
$ task | ||
task: [build] go build . | ||
task: [run] ./try-golang -onetime | ||
ENTER EXAMPLE NAME: osop_setenv | ||
[Name] "osop_setenv" | ||
[MYENV1] HELLOWORLD | ||
[HOSTNAME] HELLOWORLD | ||
[Elapsed] 61.65µs | ||
*/ | ||
|
||
} |