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
+10.1k Golang : Google Drive API upload and rename example
+26.8k Golang : Create x509 certificate, private and public keys
+13.3k Golang : How to get own program name during runtime ?
+4.7k Golang : Getting Echo framework StartAutoTLS to work
+6k Golang : Generate random Chinese, Japanese, Korean and other runes
+6.9k Golang : Embed secret text string into binary(executable) file
+3.2k PHP : Hide PHP version information from curl
+5k Nginx : How to block user agent ?
+3.7k Android Studio : Hello World example
+17k Golang : Upload big file (larger than 100MB) to AWS S3 with multipart upload
+8.8k Golang : How to detect a server/machine network interface capabilities?
+7.6k Golang : Command line file upload program to server example