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

相关推荐
Joey_friends39 分钟前
【Linux】线程详解
开发语言
_GR1 小时前
Qt开发⑧Qt的窗口_下_浮动窗口+对话框
开发语言·css·c++·qt·microsoft
Good Note1 小时前
Golang——常用库context和runtime
开发语言·爬虫·golang
清河__1 小时前
【Go】十七、grpc 服务的具体功能编写
开发语言·后端·golang
张声录12 小时前
国密算法Sm2工具类--golang实现版
开发语言·后端·golang
HH牛码2 小时前
C# 中 Array、ArrayList 和 List 的比较
开发语言·c#
zr想努力3 小时前
Lua的table类型的增删改查操作
java·开发语言·lua
Evand J4 小时前
【MATLAB代码】RSA加密和解密例程
开发语言·算法·matlab
go54631584657 小时前
本地部署 GitHub 上的 Python 人脸识别项目
开发语言·python·github
wjs20248 小时前
PHP 连接 Memcached 服务
开发语言