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
+4.9k Golang : Launching your executable inside a console under Linux
+8.2k Golang : How to control fmt or log print format?
+5.7k Golang : Reverse by word
+26k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+5.4k WARNING: UNPROTECTED PRIVATE KEY FILE! error message
+25.5k PHP : Convert(cast) string to bigInt
+44.3k Golang : Marshal and unmarshal json.RawMessage struct example
+15k Golang : Get file permission
+11.7k Golang : Convert(cast) uintptr to string example
+10k Golang : Proper way to test CIDR membership of an IP 4 or 6 address example
+14.6k Golang : How to reverse elements order in map ?
+13.8k Golang : How to check for empty array string or string?