<ul dir="auto">
<li>What version of Go are you using (<code class="notranslate">go version</code>)?</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;go version
go version go1.6 windows/amd64"><pre class="notranslate"><code class="notranslate">&gt;go version
go version go1.6 windows/amd64
</code></pre></div>
<ul dir="auto">
<li>What operating system and processor architecture are you using (<code class="notranslate">go env</code>)?</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&gt;go env
set GOARCH=amd64
set GOBIN=C:\Users\&lt;user&gt;\Development\GoSource\bin
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\&lt;user&gt;\Development\GoSource
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1"><pre class="notranslate"><code class="notranslate">&gt;go env
set GOARCH=amd64
set GOBIN=C:\Users\&lt;user&gt;\Development\GoSource\bin
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=C:\Users\&lt;user&gt;\Development\GoSource
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
</code></pre></div>
<ul dir="auto">
<li>What did you do?</li>
</ul>
<p dir="auto">The <a href="https://golang.org/pkg/path/#Base" rel="nofollow">documentation</a> gives an example on the expected behaviour of <code class="notranslate">path.Base()</code>, however, it does not actually split the trailing path element. Also, <code class="notranslate">path.Base()</code> duplicates the <code class="notranslate">\</code> in the path.</p>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="package main

import (
    &quot;fmt&quot;
    &quot;path&quot;
    &quot;strings&quot;
)

func main() {
    base := `c:\users\username`
    fmt.Println(path.Base(base))
    fmt.Println(fmt.Sprintf(&quot;%q\n&quot;, strings.SplitAfter(base, `\`)))
    lines := strings.SplitAfter(base, `\`)
    fmt.Println(lines[len(lines)-1])
}"><pre class="notranslate"><span class="pl-k">package</span> main

<span class="pl-k">import</span> (
    <span class="pl-s">"fmt"</span>
    <span class="pl-s">"path"</span>
    <span class="pl-s">"strings"</span>
)

<span class="pl-k">func</span> <span class="pl-en">main</span>() {
    <span class="pl-s1">base</span> <span class="pl-c1">:=</span> <span class="pl-s">`c:\users\username`</span>
    <span class="pl-s1">fmt</span>.<span class="pl-en">Println</span>(<span class="pl-s1">path</span>.<span class="pl-en">Base</span>(<span class="pl-s1">base</span>))
    <span class="pl-s1">fmt</span>.<span class="pl-en">Println</span>(<span class="pl-s1">fmt</span>.<span class="pl-en">Sprintf</span>(<span class="pl-s">"%q<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">strings</span>.<span class="pl-en">SplitAfter</span>(<span class="pl-s1">base</span>, <span class="pl-s">`\`</span>)))
    <span class="pl-s1">lines</span> <span class="pl-c1">:=</span> <span class="pl-s1">strings</span>.<span class="pl-en">SplitAfter</span>(<span class="pl-s1">base</span>, <span class="pl-s">`\`</span>)
    <span class="pl-s1">fmt</span>.<span class="pl-en">Println</span>(<span class="pl-s1">lines</span>[<span class="pl-en">len</span>(<span class="pl-s1">lines</span>)<span class="pl-c1">-</span><span class="pl-c1">1</span>])
}</pre></div>
<ul dir="auto">
<li>What did you expect to see?</li>
</ul>
<p dir="auto">The expected behaviour should be consistent with the <a href="https://golang.org/pkg/path/#Base" rel="nofollow">documentation examples</a>; <code class="notranslate">path.Base()</code> should return the trailing path element.</p>
<ul dir="auto">
<li>What did you see instead?</li>
</ul>
<p dir="auto"><code class="notranslate">path.Base()</code> returns the full path instead of the final path element.</p>
<p dir="auto">by <strong>steve.wangbin</strong>:</p>
<pre class="notranslate">Before filing a bug, please check whether it has been fixed since the
latest release. Search the issue tracker and check that you're running the
latest version of Go:

Run "go version" and compare against
<a href="http://golang.org/doc/devel/release.html" rel="nofollow">http://golang.org/doc/devel/release.html</a>  If a newer version of Go exists,
install it and retry what you did to reproduce the problem.

Thanks.

What steps will reproduce the problem?
If possible, include a link to a program on play.golang.org.
My program is too large to post here. the relavent function is below:
line 58: func (p *channelChatCase) prepare(account string, pos *position) (player
*gameserver.Player, err error) {
line 59:    player, err = gameserver.Login(&amp;p.env.Param, account, p.env.Password,
"")
line 60:    if err != nil {
line 61:        return nil, err
line 62:    }
line 63:    defer func() {
line 64:        if err != nil {
line 65:            player.Close()
line 66:        }
line 67:    }()
line 68:    if err := player.WaitChannel(p.channeltype); err != nil {
line 69:        return nil, err
line 70:    }
line 71:    if err := player.NewWorld(pos.mapid, pos.x, pos.y); err != nil {
line 72:        return nil, err
line 73:    }
line 74:    return player, nil
line 75: }

This function returned at line 68 and caused a panic, but the stack trace told me that
the line number where the function returns is 61.

What is the expected output?
main._func_002(0x261af0, 0x261ae8, 0xf8400009f0, 0xf840207000)
        D:/svnroot/devtool/robot/case_channelchat.go:65 +0x36
main.(*channelChatCase).prepare(0xf840217600, 0xf84006c0a9, 0x8, 0xf840217620, 0x0, ...)
        D:/svnroot/devtool/robot/case_channelchat.go:69 +0xf4

What do you see instead?
main._func_002(0x261af0, 0x261ae8, 0xf8400009f0, 0xf840207000)
        D:/svnroot/devtool/robot/case_channelchat.go:65 +0x36
main.(*channelChatCase).prepare(0xf840217600, 0xf84006c0a9, 0x8, 0xf840217620, 0x0, ...)
        D:/svnroot/devtool/robot/case_channelchat.go:61 +0xf4

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

Which operating system are you using?
windows7 64bit

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

Please provide any additional information below.</pre>