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
+7.5k Golang : How to detect if a sentence ends with a punctuation?
+14k Golang : Human readable time elapsed format such as 5 days ago
+18k Golang : Get all upper case or lower case characters from string example
+6.3k Golang : Extract sub-strings
+21.7k Golang : Encrypt and decrypt data with TripleDES
+18.1k Golang : How to log each HTTP request to your web server?
+6.4k PHP : Proper way to get UTF-8 character or string length
+8.5k Golang : Ackermann function example
+8.6k Golang : Add text to image and get OpenCV's X, Y co-ordinates example
+13.4k Golang : Generate Code128 barcode
+11.8k Golang : How to detect a server/machine network interface capabilities?
+6.6k Golang : Totalize or add-up an array or slice example