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
+19.8k Golang : Check if os.Stdin input data is piped or from terminal
+15.6k Golang : Read large file with bufio.Scanner cause token too long error
+9.2k Golang : Scramble and unscramble text message by randomly replacing words
+9.4k Golang : Detect number of active displays and the display's resolution
+28.7k Golang : Get first few and last few characters from string
+5.1k Unix/Linux/MacOSx : How to remove an environment variable ?
+5.4k Golang : Frobnicate or tweaking a string example
+6.9k Golang : Use modern ciphers only in secure connection
+6k Golang : How to get capacity of a slice or array?
+7.3k Golang : Handling Yes No Quit query input
+31.1k Golang : Get local IP and MAC address