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
+3.5k Javascript : How to show different content with noscript?
+4.4k Golang : Return multiple values from function
+20.7k Golang : Print leading(padding) zero or spaces in fmt.Printf?
+12.1k Golang : Image to ASCII art example
+37.6k Golang : Convert to io.ReadSeeker type
+16.5k Golang : How to log each HTTP request to your web server?
+24.7k Mac/Linux and Golang : Fix bind: address already in use error
+7k Golang : Qt splash screen with delay example
+7.8k Golang : Simple histogram example
+4.5k Golang : Frobnicate or tweaking a string example
+6.6k Golang : Detect sample rate, channels or latency with PortAudio
+8.9k Golang : Get current, epoch time and display by year, month and day