FAQ
hi,friend!
can you relove this problem?I have encountered this problem.
On Tuesday, November 23, 2010 8:55:32 PM UTC+8, chris dollin wrote:

On 23 November 2010 12:39, Andreas Otto <aott...@t-online.de <javascript:>>
wrote:
my problem is that the only way to convert an "interface{}",
using a "unknown" type, into an "string" is (as I know)

fmt.Sprintf("%s", ifc)

Is this right, or can I test for an "string" like interface?
You can use a type test. If X is your interface{} variable and T is
the type you want to test for -- be it an interface type or a concrete
type -- then

aT, isT := X.(T)

will set isT to true iff X has underlying type T and aT to the
corresponding
T value (the zero value if isT = false).
what is the standard in GO if something support a serialization into a
"string" object
fmt.Stringer looks like the plausible candidate.

Are you really sure you want to be doing this test? (You can test an
interface{} for equality against a string anyway ..)

Chris

--
Chris "allusive" Dollin
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 5 | next ›
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJan 30, '13 at 1:39a
activeFeb 1, '13 at 4:33p
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase