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
+6.2k Golang : Array mapping with Interface
+23.3k Golang : GORM read from database example
+5.9k Golang : Pat multiplexer routing example
+10.8k Golang : Clean formatting/indenting or pretty print JSON result
+7.9k Golang : Apply Histogram Equalization to color images
+6.5k Golang : Getting Echo framework StartAutoTLS to work
+10.5k SSL : The certificate is not trusted because no issuer chain was provided
+14.9k Golang : How to check if input from os.Args is integer?
+28.9k Golang : Remove characters from string example
+11.8k Golang : Convert IPv4 address to packed 32-bit binary format
+7.8k Golang : Find duplicate files with filepath.Walk