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.9k Swift : Convert (cast) String to Double
+10.2k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+13k Golang : Convert IP version 6 address to integer or decimal number
+9.3k Golang : How to get quoted string into another string?
+10.7k Golang : Split strings into command line arguments
+9.8k Golang : Sieve of Eratosthenes algorithm
+5k Fontello : How to load and use fonts?
+37.7k Golang : How to read CSV file
+5.2k Javascript : Get operating system and browser information
+6.9k Golang : Scan files for certain pattern and rename part of the files
+6.5k Golang : Rename part of filename
+16.5k Convert JSON to CSV in Golang