steevehook
10/22/2019 - 2:53 PM

Packages in Go (Scope)

package main

import (
	"fmt"
	"github.com/gophertuts/go-basics/constants/scope/p1"
)

const (
	Exported   = 10
	unExported = "Hello"
)

func main() {
	const (
		private = 10
		Private = "Hello"
	)

	fmt.Println("main: p1: Exported: ", p1.Exported)
	fmt.Println("main: Exported: ", Exported)
	fmt.Println("main: unExported: ", unExported)
	fmt.Println("main: Private: ", Private)
	fmt.Println("main: private: ", private)
}
package p1

import (
	"fmt"
	"github.com/gophertuts/go-basics/constants/scope/p2"
)

const (
	Exported   = "exported"
	unExported = 10
)

func init() {
	fmt.Println("p1: unExported:", unExported)
	fmt.Println("p1: p2: Exported:", p2.Exported)
}
package p2

const Exported = 10