m["Line3"].(line).content = "something"
You need to tell Go that the interface{} value is that type so it can
unbox the value.
Well, you have a map to empty interface. So m["line3"] is going to give
you an empty interface. You can't refer to a field in an empty
interface.
There is another issue, though, which is a rather tricky part of the
language. You can assign to a map index expression, but you can't
assign to a part of it. This is because you can't take the address of a
map index, so a map index is not addressable, and so you can not assign
to a field of it. This is a logical consequence of the rules, but the
end result is odd.
Anyhow, what you have to do here, assuming you want to keep the map to
an empty interface, is something like
l := m["Line3"].(line)
l.content = "something"
m["Line3"] = l
Ian
[For assignments] Each left-hand side operand must be addressable, a map index expression, or the blank identifier.
[An expression is addressable if it is] either a variable, pointer indirection, or slice indexing operation; or a field selector of an addressable struct operand; or an array indexing operation of an addressable array.
Ifxis a pointer to a struct,x.yis shorthand for(*x).y;
The reason is the following:[For assignments] Each left-hand side operand must be addressable, a map index expression, or the blank identifier.The expression i.(T), for any interface value i and type T is a type assertion (not a map index expression or the blank identifier). So we have to check if its addressable:[An expression is addressable if it is] either a variable, pointer indirection, or slice indexing operation; or a field selector of an addressable struct operand; or an array indexing operation of an addressable array.A type assertion is none of the above, so the expression i.(T) is not addressable.If T is a struct type S, then i.(S).f, where f is a field of S, is a field selector of the non-addressable struct operand i.(S), and thus isn't addressable. It also isn't a variable or a blank identifier, so it doesn't meet the requirements to be the left-hand side operand of an assignment.If T is a pointer type *S such that S is a struct type, then i.(*S).f is shorthand for (*i.(*S)).f, where f is a field of S, by the following rule:Ifxis a pointer to a struct,x.yis shorthand for(*x).y;
i.(*S) is a pointer to a struct, so this rule applies. *i.(*S) is a pointer indirection, so it is an addressable struct, so (*i.(*S)).f is a field selector of an addressable struct operand, and is therefore addressable, which makes it qualify to be the left-hand operand in an assignment.
It also isn't a variable or a blank identifier, so it doesn't meet the requirements to be the left-hand side operand of an assignment.
It also isn't a map index expression or the blank identifier, so it doesn't meet the requirements to be the left-hand side operand of an assignment.
The reason is the following:
[For assignments,] Each left-hand side operand must be addressable, a map index expression, or the blank identifier.The expression i.(T), for any interface value i and type T, is a type assertion (not a map index expression or the blank identifier). So we have to check if it's addressable:
[An expression is addressable if it is] either a variable, pointer indirection, or slice indexing operation; or a field selector of an addressable struct operand; or an array indexing operation of an addressable array.A type assertion is none of the above, so the expression i.(T) is not addressable.
If T is a struct type S, then i.(S).f, where f is a field of S, is a field selector of the non-addressable struct operand i.(S), and thus i.(S).f isn't addressable. It also isn't a map index expression or the blank identifier, so it doesn't meet the requirements to be the left-hand side operand of an assignment.If T is a pointer type *S such that S is a struct type, then i.(*S).f is shorthand for (*i.(*S)).f (where f is a field of S) by the following rule:
Ifxis a pointer to a struct,x.yis shorthand for(*x).y;
i.(*S) is a pointer to a struct, so this rule applies. *i.(*S) is a pointer indirection, which makes the result an addressable struct. (*i.(*S)).f is therefore a field selector of an addressable struct operand, which makes it addressable, so it qualifies to be the left-hand operand in an assignment.
Since i.(*S).f is shorthand for (*i.(*S)).f, it also qualifies to be the left-hand operand in an assignment.
So we have shown that i.(S).f cannot be assigned to, and that i.(*S).f can be assigned to. If we substitute the interface value m["Line3"] for i, the struct type line for S, and the field content for f, we get:
m["Line3"].(line).content cannot be assigned tom["Line3"].(*line).content can be assigned to
I hope this is [finally] clear :)