Extname
Overview
Extname returns the extension including dot (path.extname).
If you are coming from Node.js, the closest pattern is path.extname(p).
Signature
go
func Extname(p string) stringCompare: Node.js · Standard Go · gox
js
path.extname('file.txt');go
ext := filepath.Ext("file.txt")go
import "github.com/sahilkhaire/gox/path"
ext := path.Extname("file.txt")Example
go
import "github.com/sahilkhaire/gox/path"
ext := path.Extname("file.txt")Tips
Import github.com/sahilkhaire/gox/path and call Extname directly. See the comparison below for the standard library equivalent.
Standard library alternative
Use the standard library directly:
go
ext := filepath.Ext("file.txt")