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
+8.1k Golang : Handle Palindrome string with case sensitivity and unicode
+12.5k Golang : Validate email address
+7k Nginx : Password protect a directory/folder
+4.2k Javascript : Empty an array example
+9.4k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+5.9k Unix/Linux : How to test user agents blocked successfully ?
+4.5k Linux/MacOSX : Search and delete files by extension
+7.7k Golang : Dealing with struct's private part
+36.2k Golang : Integer is between a range
+8.4k Golang : Check if integer is power of four example
+8.8k Golang : Combine slices but preserve order example
+5k HTTP common errors and their meaning explained