What's C++'s `using` equivalent in golang

The following code comes close in terms of readability, but is less efficient, since the compiler cannot inline function calls anymore.

import (
    "fmt"
    "strings"
)

var (
    Sprintf = fmt.Sprintf
    HasPrefix = strings.HasPrefix
)

And, it has the side-effect of importing the names fmt and strings into the file scope, which is something that C++'s using does not do.


There is currently no such functionality in Go.

That's not to say it will never be added: there is open proposal to add "Alias declarations" to the language.

Tags:

C++

Namespaces

Go