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.7k Golang : Humanize and Titleize functions
+7.8k Golang : Example of how to detect which type of script a word belongs to
+4.9k Python : Find out the variable type and determine the type with simple test
+17.5k Golang : Get future or past hours, minutes or seconds
+10.4k Golang : Generate random integer or float number
+13.2k Golang : Handle or parse date string with Z suffix(RFC3339) example
+5.6k Golang : Shortening import identifier
+8.9k Golang : GMail API create and send draft with simple upload attachment example
+18.9k Golang : Read input from console line
+8.6k Golang : Convert(cast) []byte to io.Reader type
+14k Golang : Google Drive API upload and rename example
+15.6k Golang : rune literal not terminated error