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

相关推荐
花酒锄作田7 天前
Gin 框架中的规范响应格式设计与实现
golang·gin
郑州光合科技余经理7 天前
代码展示:PHP搭建海外版外卖系统源码解析
java·开发语言·前端·后端·系统架构·uni-app·php
feifeigo1237 天前
matlab画图工具
开发语言·matlab
西岸行者7 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
dustcell.7 天前
haproxy七层代理
java·开发语言·前端
norlan_jame7 天前
C-PHY与D-PHY差异
c语言·开发语言
多恩Stone7 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
QQ4022054967 天前
Python+django+vue3预制菜半成品配菜平台
开发语言·python·django
遥遥江上月7 天前
Node.js + Stagehand + Python 部署
开发语言·python·node.js
悠哉悠哉愿意7 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习