Go语言学习-实现一个workshop

Creating new Go packages

1、创建一个Go package,叫: MyLib

• Let's create a Go package called MyLib and use it in our program

2、在go_project文件夹下开启终端,输入指令创建go.mod文件。

bash 复制代码
go mod init go_project

• Assuming our program resides in go_project/, then type "go mod init go_project" to create a go.mod file

• The go.mod file tells Go that go_project is a module (a module contains one or more packages) -- and that our new package can be found in the current directory

3、创建一个目录,叫:MyLib

• Next, create a directory named MyLib

4、在这个目录下,创建文件,叫:Lib1.go

• In MyLib directory, create a file named Lib1.go

Using our Go packages

5、导入MyLib到我们的程序

• Import MyLib into our program

6、调用MyLib中的方法

• Call the method(s) in MyLib

Visibility in Go packages

• A package 是最小的单位 of private encapsulation(私有封装) in Go

• All identifiers defined within a package are visible within the

package

• When a package is being imported, only its exported identifiers

can be accessed

• An identifier is exported if it begins with a Capital letter

Package (Example)

#参考网站

https://go.dev/tour/list

https://www.golang-book.com/books/intro

https://yourbasic.org/golang/

https://www.digitalocean.com/community/tutorials/how-to-use-go-modules

https://github.com/golang/tools/blob/master/gopls/doc/workspace.md

相关推荐
chao1898443 小时前
基于 SPEA2 的多目标优化算法 MATLAB 实现
开发语言·算法·matlab
赏金术士3 小时前
Kotlin 习题集 · 高级篇
android·开发语言·kotlin
Cat_Rocky4 小时前
k8s-持久化存储,粗浅学习
java·学习·kubernetes
楼兰公子4 小时前
buildroot 在编译rust时裁剪平台类型数量的方法
开发语言·后端·rust
AOwhisky4 小时前
虚拟化技术学习笔记
linux·运维·笔记·学习·虚拟化技术
吴声子夜歌4 小时前
Go——并发编程
开发语言·后端·golang
一只机电自动化菜鸟5 小时前
一建机电备考笔记(33) 机电专业技术(起重技术-吊装方案)(含考频+题型)
经验分享·笔记·学习·职场和发展·课程设计
ooseabiscuit5 小时前
Laravel4.x:现代PHP框架的奠基之作
java·开发语言·php
吃好睡好便好5 小时前
博客等级升级啦
学习
小新同学^O^5 小时前
简单学习 --> Spring事务
数据库·学习·spring