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
+9.3k Golang : Qt Yes No and Quit message box example
+8k Golang : Reverse text lines or flip line order example
+5.8k Javascript : Get operating system and browser information
+13.7k Golang : convert(cast) string to float value
+32.7k Golang : How to check if a date is within certain range?
+7.7k Golang : Gomobile init produce "iphoneos" cannot be located error
+4.6k PHP : Extract part of a string starting from the middle
+5.7k Facebook : How to force facebook to scrape latest URL link data?
+7.5k Golang : How to execute code at certain day, hour and minute?
+6.9k Golang : Get Alexa ranking data example
+10k Golang : How to profile or log time spend on execution?
+5.3k PHP : Fix Call to undefined function curl_init() error