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.8k Golang : How to tokenize source code with text/scanner package?
+17.3k Golang : Read input from console line
+4.3k How to check with curl if my website or the asset is gzipped ?
+14.3k Golang : Get IP addresses of a domain name
+18.8k Golang : Convert date string to variants of time.Time type examples
+9.9k Golang : Post data with url.Values{}
+12.7k Golang : Reset buffer example
+17.8k Swift : Convert (cast) Int to int32 or Uint32
+7.5k Yum Error: no such table: packages
+4.3k Unix/Linux : How to find out the hard disk size?
+24.1k Golang : How to write CSV data to file
+8.4k Golang : Detect number of faces or vehicles in a photo