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
+13.4k PHP : Convert(cast) int to double/float
+7.7k Golang : Search folders for file recursively with wildcard support
+16.2k Golang : Get current file path of a file or executable
+1.7k Golang : How to call function inside template with template.FuncMap
+6.2k Golang : Generate Code128 barcode
+19.9k Golang : How do I convert int to uint8?
+3.9k Golang : Of hash table and hash map
+10.9k Golang : Convert long hexadecimal with strconv.ParseUint example
+5.2k Golang : Sort and reverse sort a slice of floats
+11.6k Golang : Check if directory exist and create if does not exist
+4k Golang : Format strings to SEO friendly URL example
+6.1k Golang : Fix image: unknown format error