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
+8.1k Golang : Tell color name with OpenCV example
+7.4k Golang : Get YouTube playlist
+8.1k Golang : Get final or effective URL with Request.URL example
+14.3k Golang : Parsing or breaking down URL
+15.5k Golang : rune literal not terminated error
+4.7k Fix Google Analytics Redundant Hostnames problem
+4k Detect if Google Analytics and Developer Media are loaded properly or not
+16.3k CodeIgniter/PHP : Create directory if does not exist example
+79.8k Golang : How to return HTTP status code?
+16.7k Golang : Gzip file example
+10.7k Android Studio : Checkbox for user to select options example
+19.2k Golang : Execute shell command