Convert interface to struct

Have a look at Type assertions chapter in Go reference. It states:

x.(T)

More precisely, if T is not an interface type, x.(T) asserts that the dynamic type of x is identical to the type T.

Types CommandID and Field are not identical as described in Type identity.

A defined type is always different from any other type.

Both types CommandId and Fields are defined as described in Type definitions.

A type definition creates a new, distinct type with the same underlying type and operations as the given type, and binds an identifier to it.

TypeDef = identifier Type .

You can only do

field, ok := f.(*CommandID)

or

field, ok := f.(*Language)

As @mkopriva mentioned in the comment, you can do type conversion later to *Field but this it does not seem to be your goal.

Other solution is to introduce a Field interface with Set and Get methods. Then you will need to provide an implementation for every implementing type.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)