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

The method of obtaining the resolution of display by pyqt5

The code is as follows import sys from PyQt5.QtWidgets import QApplication, QWidget class Example(QWidget): def __init__(self): super().__init__() self.initUI() #Interface drawing to initui method def initUI(self): self.desktop = QApplication.desktop() #Get display resolution size self.screenRect = self.desktop.screenGeometry() self.height = self.screenRect.height() self.width = self.screenRect.width() print(self.height) print(self.width) #Show window self.show() if __name__ == ‘__main__’: #Create applications and objects app […]