Skip to content

Commit

Permalink
Add examples/basic/osop/environ.go
Browse files Browse the repository at this point in the history
  • Loading branch information
devlights committed Feb 26, 2024
1 parent d6c5ee3 commit d8c79b5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions examples/basic/osop/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
| -------------- | ------------------- | ------------------------------------- |
| mkdir.go | osop_mkdir | os.Mkdir/MkdirAllのサンプルです. |
| listprocess.go | osop_list_processes | プロセスリストを取得するサンプルです. |
| environ.go | osop_environ | os.Environ()のサンプルです。 |
33 changes: 33 additions & 0 deletions examples/basic/osop/environ.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package osop

import (
"os"
"strings"

"github.com/devlights/gomy/output"
)

// Environ は、os.Environ()のサンプルです。
//
// os.Environ() は、現在の環境変数の値を key=value 形式の文字列で返す。
// 戻り値は []string 。
//
// # REFERENCES
// - https://pkg.go.dev/[email protected]#Environ
func Environ() error {
for _, env := range os.Environ() {
var (
kv = strings.Split(env, "=")
k = kv[0]
v = kv[1]
)

if !strings.HasPrefix(k, "H") {
continue
}

output.Stdoutl("[env]", k, v)
}

return nil
}
1 change: 1 addition & 0 deletions examples/basic/osop/examples.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ func NewRegister() mapping.Register {
func (r *register) Regist(m mapping.ExampleMapping) {
m["osop_mkdir"] = Mkdir
m["osop_list_processes"] = ListProcesses
m["osop_environ"] = Environ
}

0 comments on commit d8c79b5

Please sign in to comment.