3. GO – Project Structure and Package Access Permissions

Time:2019-8-11

3.1. Project structure in GoLand

(1) Create a standard Go project in GoLand

(2) GoLand configuration

Create Project Learn-Go

File-settings-go-GOPATH-Add

Create the SRC directory under the project directory, the demo directory under the SRC directory, and the demo.go file under the demo directory.

//Learn_Go/src/demo/demo.go
package demo

import "fmt"

func Demo()  {
	Fmt. Println ("Execute demo")
}

Create the main.go file under the project directory

//Learn_Go/main.go
package main

import "demo"

func main()  {
	Demo. Demo ()// Execute demo
}

Directory results

 

Right-click on item – > Run – > go_build Learn_Go

 

 

3.2. Packet and Packet Level Access Rights

The lowercase in the same package is accessible, and the other packages must be capitalized to access it.

Directory results

 

 demo1.go

//Learn_Go/src/demo/demo1.go
package demo

import "fmt"

func demo1()  {
	Fmt. Println ("Execute demo111")
}

demo2.go

//Learn_Go/src/demo/demo2.go
package demo

import "fmt"

func Demo2()  {
	Fmt. Println ("Execute demo222")
	Demo1 ()// accessible in the same package, no capitalization is required
}

main.go

//Learn_Go/main.go
package main

import "demo"

func main()  {
	demo.Demo2()
}

// Results
Execute demo222
Execute demo111

  

Recommended Today

Implementation of PHP Facades

Example <?php class RealRoute{ public function get(){ Echo’Get me’; } } class Facade{ public static $resolvedInstance; public static $app; public static function __callStatic($method,$args){ $instance = static::getFacadeRoot(); if(!$instance){ throw new RuntimeException(‘A facade root has not been set.’); } return $instance->$method(…$args); } // Get the Facade root object public static function getFacadeRoot() { return static::resolveFacadeInstance(static::getFacadeAccessor()); } protected […]