<p dir="auto">I would like to propose the addition of another method to <code class="notranslate">reflect.StructTag</code>. The proposed change is very simple, and I'm happy to produce a design document and a PR. I have filed this issue to see if there is any likelihood of this change being accepted.</p>
<p dir="auto">The <code class="notranslate">reflect.StructTag</code> currently has one method, <code class="notranslate">Get</code>, which makes it easy to extract the value for the associated key from the tag. What it does not do, however, is indicate if the key exists with an empty value.</p>
<p dir="auto">So in the following example, the <code class="notranslate">Get</code> method will return the same value for the <code class="notranslate">db</code> tag assocated with the <code class="notranslate">Name</code> field as for the <code class="notranslate">db</code> tag associated with the <code class="notranslate">Address</code> field, but there is a difference in the meaning.</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="struct {
    Name    string `db:&quot;&quot; json:&quot;-&quot;`
    Address string  
}"><pre class="notranslate"><span class="pl-k">struct</span> {
    <span class="pl-c1">Name</span>    <span class="pl-smi">string</span> <span class="pl-s">`db:"" json:"-"`</span>
    <span class="pl-c1">Address</span> <span class="pl-smi">string</span>  
}</pre></div>
<p dir="auto">It could be argued that this is a pretty simple function and should not be added to the Go standard library. I am suggesting that it should be added because any third-party implementation requires some duplication of the code for the <code class="notranslate">Get</code> method in the standard library. Duplicating the code from the Go standard library presents at least two challenges:</p>
<ul dir="auto">
<li>There is an ongoing maintenance overhead of tracking any future changes to the Go standard library.</li>
<li>The Go BSD license requires distributing the Go copyright notice and conditions with any redistribution of source code. Not a huge deal, but an inconvenience that can be omitted by adding <code class="notranslate">Lookup</code> to the standard libary.</li>
</ul>
<p dir="auto">Note also that there was a similar addition in Go 1.5 in the <code class="notranslate">os</code> package, where the <code class="notranslate">LookupEnv</code> function was introduced to complement the <code class="notranslate">GetEnv</code> function.</p>
<h2 dir="auto">Proposed New Method</h2>
<p dir="auto"><strong>func (StructTag) Lookup</strong></p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="func (tag StructTag) Lookup(key string) (string, bool)"><pre class="notranslate"><span class="pl-k">func</span> (<span class="pl-s1">tag</span> <span class="pl-smi">StructTag</span>) <span class="pl-en">Lookup</span>(<span class="pl-s1">key</span> <span class="pl-smi">string</span>) (<span class="pl-smi">string</span>, <span class="pl-smi">bool</span>)</pre></div>
<p dir="auto">Lookup returns the value associated with key in the tag string. If the key is present in the tag the value (which may be empty) is returned and the boolean is true. Otherwise the returned value will be empty and the boolean is false. If the tag does not have the conventional format, the value returned by Lookup is unspecified.</p>
<pre class="notranslate">Before filing a bug, please check whether it has been fixed since
the latest release: run "hg pull -u" and retry what you did to
reproduce the problem.  Thanks.

What steps will reproduce the problem?
Try the program:

package main

import "fmt"

func f(ch chan int) (n int) {
        select {
        case n := &lt;-ch:
                fmt.Printf("n=%d\n",n)
                return
        }
        panic("x")
}

func main() {
        ch := make(chan int)
        go func(){
                ch &lt;- 5
        }()
        fmt.Printf("f=%d\n",f(ch))
}

What is the expected output? What do you see instead?

What you MAY expect is (see discussion below):
n=5
f=5

What you see is:
n=5
f=0

What is your $GOOS?  $GOARCH?
darwin, amd64

Which revision are you using?  (hg identify)
613f36280394+ tip

Please provide any additional information below.

This situation has created sneaky bugs in my programs.
I think that either, the correct behavior should be to
output:
n=5
f=5
Or, when the compiler sees the reassignment of an 
existing variable in "case n := &lt;-ch:", it should output
a compiler error, just like it would do if you had
a clause like "n := 4" in the body of f().</pre>