Golang : Shortening import identifier
In Golang, we often import external packages from third party sources and ended with import statement that look like this example :
import (
"bytes"
"github.com/somelongname/verylongnamepackage"
"fmt"
"github.com/disintegration/imaging"
"image"
)
now, if you don't want to type in the verylongnamepackage
each time you want to call a function in it. You can shorten the verylongnamepackage
.
just change to
import (
"bytes"
vlongname "github.com/somelongname/verylongnamepackage"
"fmt"
IG "github.com/disintegration/imaging"
"image"
)
and then instead of verylongnamepackage.SomeFunction()
, you just invoke it by vlongname.SomeFunction()
.
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+6.1k Golang : Array mapping with Interface
+9k Golang : Get escape characters \u form from unicode characters
+3.8k JavaScript : Rounding number to decimal formats to display currency
+27.8k Golang : How to create new XML file ?
+9.2k Golang : Convert file unix timestamp to UTC time example
+14k Golang : Force download file example
+8.2k Golang : Temperatures conversion example
+2.7k Java : Get FX sentiment from website example
+7.6k Golang : How to join strings?
+10.4k Golang : Surveillance with web camera and OpenCV
+12.2k Golang : Read from buffered reader until specific number of bytes
+13.2k Golang : Reset buffer example