Go and namespaces: is it possible to achieve something similar to Python?

I wonder if there is a way to use namespaces in Go just like Python does.

In Python, if I have the following files containing functions:

/a.py
    def foo():
/b.py
    def bar():

I can access fooand barin the third Python file as follows:

import a
a1 = a.foo()
import b
b1 = b.bar()

I'm having difficulty finding some documentation on Go namespaces. How are namespaces implemented? With packageand import? Or importintended for external libraries?

, , . , , , . , ( ).

+4
1

Go Python - . Python, , Go . , .

, Python, $GOPATH/src/a/a.go :

package a

import "fmt"

func Foo() {
    fmt.Println("a.Foo")
}

:

package main

import "a"

func main() {
    a.Foo()
}

, a . , ( foo foo).

Go, . , import "./a", a a/a.go .

+7

Source: https://habr.com/ru/post/1535957/


All Articles