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
+11.1k Golang : Read until certain character to break for loop
+12.5k Golang : Forwarding a local port to a remote server example
+25.7k Golang : missing Mercurial command
+33.8k Golang : convert(cast) bytes to string
+4.6k Javascript : Detect when console is activated and do something about it
+5.8k Golang : Markov chains to predict probability of next state example
+22.1k Golang : Join arrays or slices example
+36.5k Golang : Save image to PNG, JPEG or GIF format.
+8.3k Golang : Auto-generate reply email with text/template package
+5.9k Golang : Generate multiplication table from an integer example
+9.1k Golang : Serving HTTP and Websocket from different ports in a program example
+3.8k Golang : Switch Redis database redis.NewClient