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 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
小羊没烦恼!2 天前
初探性能优化——2个月到4小时的性能提升
java·开发语言·windows·算法·c#
XiHongShi20162 天前
STM32F407 RTC定时器例程,建议保存
stm32·单片机·学习
爱吃苹果的日记本2 天前
离散数学第六课
学习·离散数学
伞伞悦读2 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python
ttwuai2 天前
Go开源后台管理系统推荐:怎么按技术栈和边界比较4个官方仓库?
golang·gin
C语言小火车2 天前
C/C++ 为什么需要编译器?
开发语言·c++
AI职业加油站2 天前
AI智能体应用工程师证书:政策红利下的职业新风口
大数据·运维·人工智能·学习·职场发展
codeejun2 天前
每日一Go·MySQL-5、锁机制全解析
云原生·golang