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
+17.4k Golang : Login and logout a user after password verification and redirect example
+8.9k Golang : Temperatures conversion example
+7.3k Golang : Error reading timestamp with GORM or SQL driver
+6.7k Web : How to see your website from different countries?
+10.7k Golang : Intercept and process UNIX signals example
+11.2k Golang : Handle API query by curl with Gorilla Queries example
+10.5k Golang : Natural string sorting example
+6.4k Golang : Get expvar(export variables) to work with multiplexer
+6.9k Golang : Example of custom handler for Gorilla's Path usage.
+6.6k Golang : Decode XML data from RSS feed
+85k Golang : How to convert character to ASCII and back
+14.5k Golang : How to check for empty array string or string?