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
+50.9k Golang : Disable security check for HTTPS(SSL) with bad or expired certificate
+55.1k Golang : Unmarshal JSON from http response
+7.2k Golang : alternative to os.Exit() function
+36.2k Golang : Convert(cast) int64 to string
+5.7k Cash Flow : 50 days to pay your credit card debt
+7.6k Golang : Command line ticker to show work in progress
+8.6k Golang : Combine slices but preserve order example
+41k Golang : How to count duplicate items in slice/array?
+11.5k SSL : The certificate is not trusted because no issuer chain was provided
+12.1k Golang : md5 hash of a string
+6.1k Golang : Extract XML attribute data with attr field tag example
+4.7k Which content-type(MIME type) to use for JSON data