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
+15k Golang : How to extract links from web page ?
+17.3k Golang : Set, Get and List environment variables
+7k Golang : Find relative luminance or color brightness
+29.3k Golang : bufio.NewReader.ReadLine to read file line by line
+18.4k Golang : How to count the number of repeated characters in a string?
+3.9k Fix Google Analytics Redundant Hostnames problem
+2.8k Java : Random alphabets, alpha-numeric or numbers only string generator
+24.9k Golang : Convert file content into array of bytes
+12.6k Golang : How to convert a number to words
+25.9k Golang : Convert integer to binary, octal, hexadecimal and back to integer
+5.1k Golang : Create new color from command line parameters
+10.1k CodeIgniter : How to check if a session exist in PHP?