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
+18.7k Golang : Logging with logrus
+5k Unix/Linux : secure copying between servers with SCP command examples
+10k Golang : Get current, epoch time and display by year, month and day
+30.5k Golang : How to redirect to new page with net/http?
+7.7k Golang : How to stop user from directly running an executable file?
+9.8k PHP : Get coordinates latitude/longitude from string
+27.1k Golang : Find files by extension
+18k Golang : Iterate linked list example
+7.3k Golang : Array mapping with Interface
+19.6k Golang : How to count the number of repeated characters in a string?
+7.1k Golang : How to solve "too many .rsrc sections" error?
+13.3k Golang : Convert(cast) uintptr to string example