What's C++'s using some_namespace::object
equivalent in golang?
According to the question here
I can get using namespace common
with statement below:
import (
. "common"
)
But this would import the entire namespace. Right now I only want to use, say platform
definition, something like using common::platform
Is there an equivalent for this in Go, so that I don't have to type common.platform
all the time?
"=" is assignment,just like other language. <- is a operator only work with channel,it means put or get a message from a channel. channel is an important concept in go,especially in concurrent programming.
Underlying typeEach type in Go has something which is called an underlying type. Universe block contains some predeclared identifiers binding to types like boolean, string or numeric. For each predeclared type T its underlaying type is T (no trap here).
We can use %T string formatting flag to get type of variable in Go. This is the simplest way to check of find the type of variable in Go language. '%T' flag is part of “fmt” package, we can use it along with fmt. Printf to display the type of variable.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With