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
+7.7k Python : Fix SyntaxError: Non-ASCII character in file, but no encoding declared
+8.7k Golang : Get all countries currencies code in JSON format
+4.6k Golang : If else example and common mistake
+5.4k Golang : Debug with Godebug
+11.2k Golang : Print UTF-8 fonts on image example
+6.3k Golang : Accessing dataframe-go element by row, column and name example
+14.5k Golang : Intercept Ctrl-C interrupt or kill signal and determine the signal type
+17.3k Golang : Iterating Elements Over A List
+10.6k Golang : Generate DSA private, public key and PEM files example
+16.5k Golang : Linked list example
+7.6k Golang: Prevent over writing file with md5 hash
+13.2k Golang : syscall.Socket example