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
+16.3k Golang : Get IP addresses of a domain name
+10k Golang : Use regular expression to get all upper case or lower case characters example
+36.1k Golang : How to split or chunking a file to smaller pieces?
+4.3k Linux/MacOSX : Search and delete files by extension
+41.5k Golang : How do I convert int to uint8?
+5.5k Unix/Linux : How to find out the hard disk size?
+46.2k Golang : Encode image to base64 example
+7k Nginx : How to block user agent ?
+17.7k Golang : Simple client server example
+7.1k Golang : Null and nil value
+15.1k Golang : Accurate and reliable decimal calculations
+18.2k Golang : Read binary file into memory