高软lab:VSCode中编译并调试MENU.go程序,并添加版本库(win11)

sunfa_jasme 2023-03-19 19:52:34

一、配置go语言开发环境

Go语言官网中下载Windows安装包(*.msi文件),并配置环境变量:

命令行中输入:

go env

出现以下内容,表明Go开发环境配置成功。

下载VSCode对go语言的支持:

还需要安装go调试工具dlv,而安装该工具依赖go.mod文件。命令如下:

go mod init example.com/m/v2
go get github.com/go-delve/delve/cmd/dlv

若第二条命令可能由于网络原因不能执行,可采用git工具来进行安装:

cd $GOPATH/src/
git clone https://github.com/derekparker/delve.git
cd delve/cmd/dlv/
go build
go install

 

二、编写并调试MENU程序

编写Go语言程序如下:

package main
import "fmt"

func main() {
	fmt.Print("\nMENU offers developers reference of environment configuration and workflow.\n\n")
	fmt.Print("\tType in your command or 'help' to learn more. Press 'Ctrl+C' to quit\n\n")
	for true {
		fmt.Print(">>>>");
		var stdin string
		fmt.Scanln(&stdin)
		if stdin == "help" {
			fmt.Println("\t\thelp\t\tshow commands of MENU")
			fmt.Println("\t\thello\t\tan easy 'hello' output")
			fmt.Println("\t\texit\t\texit MENU immediately")
		} else if stdin == "hello" {
			fmt.Println("\t\tHello, World!")
		} else if stdin == "exit" {
			fmt.Println("\t\tSee you again!\n")
			break
		} else {
			fmt.Println("\t\tUnknown command. please type 'help' to learn more.")
		}
	}
}

采用“基本路径测试”的思想对代码进行调试,测试用例如下:

"exit"
"help","exit"
"hello","exit"
"help","hello","exit"
"hello","help","exit"

调试过程:

 

三、创建版本库

采用gitee创建远程仓库

本地git bash中输入以下命令:

git init
git remote add origin [repo link]
git pull --rebase origin master
git add .
git commit -m [log info]
git push

本地仓库、远程仓库均进行检查,保持一致,创建版本库成功。

 

 

参考资料

孟宁 / 软件工程

知乎_Go语言开发环境配置

简书_Golang调试工具Delve安装及使用

 

学号:末三位166


 

 

...全文
122 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

571

社区成员

发帖
与我相关
我的任务
社区描述
软件工程教学新范式,强化专项技能训练+基于项目的学习PBL。Git仓库:https://gitee.com/mengning997/se
软件工程 高校
社区管理员
  • 码农孟宁
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧