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
+4.2k Javascript : Empty an array example
+12.1k Golang : Convert decimal number(integer) to IPv4 address
+18.7k Golang : Aligning strings to right, left and center with fill example
+25.8k Golang : convert rune to integer value
+5.7k Golang : Configure crontab to poll every two minutes 8am to 6pm Monday to Friday
+19.7k Golang : Example for DSA(Digital Signature Algorithm) package functions
+8.4k Golang: Prevent over writing file with md5 hash
+14.2k Golang : Compress and decompress file with compress/flate example
+21.4k Golang : Clean up null characters from input data
+5.4k Golang : The Tao of importing package
+30.3k Golang : How to declare kilobyte, megabyte, gigabyte, terabyte and so on?