struct之demo1
原创
©著作权归作者所有:来自51CTO博客作者kq1983的原创作品,请联系作者获取转载授权,否则将追究法律责任
Storageos1
package mystruct
type Storageos1 struct {
PodNamespace string
PvName string
VolName string
volNamespace string
ReadOnly bool
description string
pool string
fsType string
SizeGB int
Labels map[string]string
}
type StorageosMounter struct {
*Storageos1
// The directory containing the StorageOS devices
DeviceDir string
}
test
package main
import (
"fmt"
"mystruct"
)
func main() {
var a2 = new(mystruct.Storageos1)
a2.PvName = "d"
a2.ReadOnly = false
a2.SizeGB = 100
var dict map[string]string //定义dict为map类型
dict = make(map[string]string) //让dict可编辑
dict["blue"] = "蓝"
dict["yellow"] = "黄"
dict["red"] = "红"
a2.Labels = dict
var sm = new(mystruct.StorageosMounter)
sm.Storageos1 = a2
sm.DeviceDir = "d:\\logs\\golang"
fmt.Printf("yellow=%s \n", dict["yellow"])
fmt.Printf("size gb=%d \n", sm.Storageos1.SizeGB)
}