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
+17.4k Unmarshal/Load CSV record into struct in Go
+11.9k Golang : Linear algebra and matrix calculation example
+8.6k Golang : Identifying Golang HTTP client request
+5.7k Golang : Reverse by word
+15.1k Golang : Fix cannot convert buffer (type *bytes.Buffer) to type string error
+15.3k CodeIgniter/PHP : Create directory if does not exist example
+5.7k Golang : Get expvar(export variables) to work with multiplexer
+20.3k Golang : Convert seconds to minutes and remainder seconds
+8k Random number generation with crypto/rand in Go
+17.1k Golang : Read binary file into memory
+13.3k Golang : Get URI segments by number and assign as variable example
+9.4k Swift : Convert (cast) String to Integer