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
+11.4k Golang : HTTP response JSON encoded data
+10.1k Golang : Format numbers to nearest thousands such as kilos millions billions and trillions
+13k Golang : How to determine if user agent is a mobile device example
+24.5k Golang : Get executable name behind process ID example
+7.8k Golang : Apply Histogram Equalization to color images
+18.2k Golang : Compare floating-point numbers
+7.1k Golang : Oanda bot with Telegram and RSI example
+6.2k Golang : Use modern ciphers only in secure connection
+9.4k Golang : Underscore string example
+7.6k Linux/Unix : fatal: the Postfix mail system is already running
+10.3k Golang : How to flush a channel before the end of program?
+7.9k Golang : Generate EAN barcode