[Go] golang x.(type) 用法
发布时间:2021-05-21 06:47:52 所属栏目:大数据 来源: https://www.jb51.cc
导读:golang x.(type) 用法 x.(type)只能在switch中使用,和switch case配合使用,获取到类型 ? func MyPrintf(args ... interface {}) { for _,arg := range args { switch arg. (type) { case int: fmt .Println(arg,"is an int value." ) case string : case int
golang x.(type) 用法 ? func MyPrintf(args ...interface{}) { for _,arg := range args { switch arg.(type) { case int: fmt.Println(arg,"is an int value.") case string:case int64:default:) } } } 在go-imap中看到使用 switch h := p.Header.(type) { case *mail.InlineHeader: // This is the message's text (can be plain-text or HTML) b,_ := IoUtil.ReadAll(p.Body) log.Println("Got text: ",string(b)) mail.AttachmentHeader: This is an attachment filename,_ := h.Filename() log.Println("Got attachment: ",1)"> filename) } ? (编辑:北几岛) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |