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
+24.2k Golang : How to read integer value from standard input ?
+35.3k Golang : Convert(cast) int64 to string
+3.9k Golang : Customize scanner.Scanner to treat dash as part of identifier
+23.7k Golang : Get current file path of a file or executable
+11.4k Golang : "https://" not allowed in import path
+32.6k Golang : Proper way to set function argument default value
+5k Golang : How to verify input is rune?
+7.1k Golang : Auto-generate reply email with text/template package
+13.3k Golang : Convert(cast) int to float example
+18.2k Golang : Convert seconds to human readable time format example
+8.4k Golang : Quadratic example
+14.8k Golang : Generate universally unique identifier(UUID) example