map[string]interface{} is not the same as map[string]string. Type interface{} is not the same as type string.

If they are both map[string]string:

package main

import "fmt"

func main() {
v := map[string]string{"hello": "world"}
checkCast(v) } func checkCast(v interface{}) {
_, isCorrectType := v.(map[string]string)
if !isCorrectType {
fmt.Printf("incorrect type")
return
}
}

Output:

[no output]

The statement v.(map[string]string) is a type assertion, not a cast.

The Go Programming Language Specification

Type assertions

For an expression x of interface type and a type T, the primary expression

x.(T)

asserts that x is not nil and that the value stored in x is of type T. The notation x.(T) is called a type assertion.


Go has conversions.

The Go Programming Language Specification

Conversions

Conversions are expressions of the form T(x) where T is a type and x is an expression that can be converted to type T.

answered Jul 4 '14 at 19:45
peterSO

101k16172186

最新文章

  1. bzoj 2648 KD-tree
  2. 去除select的样式
  3. UIKit框架之UITouch
  4. 初识canvas,使用canvas做一个百分比加载进度的动画
  5. Strobogrammatic Number
  6. java去处重复输出
  7. js方法收藏
  8. hdu 3549 Flow Problem 网络流
  9. python(7)–类的多态实现
  10. 学习笔记之Linux Shell脚本教程:30分钟玩转Shell脚本编程
  11. 验证角谷猜想(hd1279)
  12. 用邻接表实现DFS和BFS
  13. uva 1025
  14. 关于Java通过JNI调用C 动态链接库(DLL)
  15. 移动H5开发入门知识,CSS的单位汇总与用法
  16. Red Hat 9.0 Linux 分辨率修改
  17. SQLServer修改表数据
  18. LeetCode(58): 最后一个单词的长度
  19. 添加 vip
  20. Xib给特定view添加手势

热门文章

  1. FMZ发明者量化平台回测机制说明
  2. 计算1-9总共九个数字可以满足abc+def=hij这样的式子
  3. editor does not cantain a main type——解决
  4. 怎么才能记住java线程的start()和run()谁是启动方法
  5. 小菜鸟之SSM框架
  6. python并发编程之多进程(实践篇)
  7. S02_CH09_UART串口中断实验
  8. 数据库(mysql和oracle)
  9. Kirinriki 2017多校
  10. arcgis js 之 渔网工具(调用地图服务)