Basename
Overview
Basename returns the last element (path.basename).
If you are coming from Node.js, the closest pattern is path.basename(p).
Signature
go
func Basename(p string) stringCompare: Node.js · Standard Go · gox
js
path.basename('/foo/bar.txt');go
name := filepath.Base("/foo/bar.txt")go
import "github.com/sahilkhaire/gox/path"
name := path.Basename("/foo/bar.txt")Example
go
import "github.com/sahilkhaire/gox/path"
name := path.Basename("/foo/bar.txt")Tips
Import github.com/sahilkhaire/gox/path and call Basename directly. See the comparison below for the standard library equivalent.
Standard library alternative
Use the standard library directly:
go
name := filepath.Base("/foo/bar.txt")