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.2k Golang : Gorrila mux.Vars() function example
+7.8k Golang : Convert(cast) io.Reader type to string
+9.5k Golang : Find the length of big.Int variable example
+15.6k Golang : Find location by IP address and display with Google Map
+41.1k Golang : How to check if a string contains another sub-string?
+3.5k Golang : Fix go-cron set time not working issue
+15.4k nginx: [emerg] unknown directive "ssl"
+9.9k Golang : Format strings to SEO friendly URL example
+13.9k Golang : Convert spaces to tabs and back to spaces example
+6.8k Golang : Derive cryptographic key from passwords with Argon2
+9.1k Golang : Get SPF and DMARC from email headers to fight spam
+9.5k Facebook : Getting the friends list with PHP return JSON format