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

相关推荐
蓝天智能2 分钟前
QT MVC中View的特点及使用注意事项
开发语言·qt·mvc
木觞清21 分钟前
喜马拉雅音频链接逆向实战
开发语言·前端·javascript
wuxuanok34 分钟前
苍穹外卖 —— 公共字段填充
java·开发语言·spring boot·spring·mybatis
偷光38 分钟前
浏览器中的隐藏IDE: Console (控制台) 面板
开发语言·前端·ide·php
larry_dongy1 小时前
【学习记录】vscode+ros2+cpp调试
vscode·学习
LL_break2 小时前
线程1——javaEE 附面题
java·开发语言·面试·java-ee
MOON404☾2 小时前
Rust 与 传统语言:现代系统编程的深度对比
开发语言·后端·python·rust
先知后行。2 小时前
Reactor模型和类图设计
java·开发语言
清欢ysy2 小时前
Cannot find module ‘@next/bundle-analyzer‘
开发语言·javascript·arcgis
递归不收敛2 小时前
吴恩达机器学习课程(PyTorch适配)学习笔记:1.5 决策树与集成学习
pytorch·学习·机器学习