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
+5.8k PageSpeed : Clear or flush cache on web server
+5.7k Golang : Grab news article text and use NLP to get each paragraph's sentences
+9.1k Mac OSX : Get a process/daemon status information
+14.3k Golang : Missing Bazaar command
+10.5k Golang : Command line file upload program to server example
+51.6k Golang : How to get time in milliseconds?
+13.2k Generate salted password with OpenSSL example
+31.1k Golang : How to convert(cast) string to IP address?
+6.9k Golang : Transform lisp or spinal case to Pascal case example
+8.6k Golang : Find network service name from given port and protocol
+16.8k Golang : Covert map/slice/array to JSON or XML format
+12.9k Golang : Convert(cast) int to int64