<p dir="auto">The rules for struct identity require that two identical structs have identical tags.</p>
<p dir="auto">This plays into the rules for assignments and conversions of structs in unfortunate ways:</p>
<p dir="auto">There appears to be no way to assign or even convert a struct with tags to another struct with different or no tags, wether that other struct is named or unnamed:</p>
<p dir="auto"><a href="http://play.golang.org/p/6FZcWSIc9w" rel="nofollow">http://play.golang.org/p/6FZcWSIc9w</a></p>
<p dir="auto">I think we're overly restrictive here. For instance, if I wanted to convert a struct with json tags to a struct with tags for some other encoding (to convert from one encoding to another), I actually have to copy all the fields by hand.</p>
<p dir="auto">This seems counter-intuitive. I would have expected that I could go via an unnamed struct, or at the very least use an explicit conversion.</p>
<p dir="auto">I'm thinking that perhaps we should relax the rules here. One might be to remove again the requirement of identical tags for struct identity (simplest); or perhaps to relax the rules for assignments and conversions of structs.</p>
<pre class="notranslate">Run this:

package main

type Message struct {
    Id   int    `db:"id"`
    Text string `db:"text"`
}

type Message2 struct {
    Id   int    `json:"id" xml:"id,attr"`
    Text string `json:"text"`
}

func main() {
    msg := Message{1, "Hello"}
    msg2 := Message2(msg)
    _ = msg2
}

What is the expected output?

[no output]

What do you see instead?

cannot convert msg (type Message) to type Message2

Which compiler are you using (5g, 6g, 8g, gccgo)?

Which version are you using?  (run 'go version')

go version devel +d744da8c8cbf Wed Sep 25 16:18:33 2013 -0400 darwin/amd64

Please provide any additional information below.

I'm trying to decouple my database layer from my service layer into separate packages.
Tags in one package are only relevant to that package. What I'd like to do is re-define
the struct in my service layer and cast it from the database layer. The fields inside
the struct are otherwise exactly the same, besides the tags.

Unfortunately it won't cast unless the tags are also exactly the same. The only solution
I have at this point is put the structs in a "common" package that both the
database and service layers share. But then I'm mixing tags...</pre>