Go入门笔记-17 type func自定义函数结合Map使用

1、代码

package main

import "fmt"

type Get func(serviceName string) interface{}

func get1(serviceName string) interface{} {
	return serviceName
}

var a = func(get Get, serviceName string) interface{} {
	return get(serviceName)
}

type ServiceMap map[string]Get

func main() {
	fmt.Println(a(get1, "aaa"))
	var bMap = ServiceMap{"1": get1}
	fmt.Println(bMap["1"]("bbb"))

}

  

2、输出结果

 

posted @ 2021-08-13 13:17  zhaogaojian  阅读(146)  评论(0编辑  收藏  举报