Created
July 2, 2018 12:00
-
-
Save ksakae1216/8bc6953454cbbbb647327e7d6ad22044 to your computer and use it in GitHub Desktop.
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
package funcpkg | |
import "fmt" | |
// MapFunc マップのサンプルです | |
func MapFunc() { | |
// マップ作成 | |
enviroment := map[string]string{ | |
"OS": "Windows", | |
"Lang": "Golang", | |
"Web": "nginx", | |
} | |
// 個別に値セット | |
enviroment["DB"] = "mongoDB" | |
// 格納順は補償されない | |
fmt.Println("マップ全て -> ", enviroment) | |
fmt.Println("キー指定 -> ", enviroment["Lang"]) | |
fmt.Println("存在しないキー -> ", enviroment["Framework"]) | |
// キーの削除 | |
delete(enviroment, "Web") | |
// キーの存在確認 | |
key, exist := enviroment["Web"] | |
if exist { | |
fmt.Println(key, "は存在する") | |
} else { | |
// ここにくる場合は、keyはnil | |
fmt.Println("Webは存在しない") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment