高级软件工程Lab1

Godzili_A 2023-03-19 17:07:20

实验简介

选用go或rust编写menu项目,创建一个版本库(gitee或github),采用VSCode作为编译调试环境。

实验环境

Ubuntu22.04
VSCode1.7.61
go1.20.2 linux/amd64

实验内容

1.配置go语言环境

下载go安装包

$ wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz

解压go安装包

$ sudo tar -C  /usr/local/ -xzvf go1.20.2.linux-amd64.tar.gz

检查go版本

$ cd /usr/local/go
$ bin/go version
go version go1.20.2 linux/amd64

配置环境变量

$ sudo vim /etc/profile
# 添加到文件末尾
export GOROOT=/usr/local/go
export GOPATH=/usr/local/gopath
export PATH=$PATH:$GOROOT/bin

配置生效

$ source /etc/profile

设置go modules配置

$ go env -w GO111MODULE=on
$ go env -w GOPROXY=https://goproxy.io,direct

可以输入以下命令查看go的环境

$ go env

2.在VSCode中下载go语言插件

安装go插件

img

使用快捷键Ctrl+Shift+p,搜索Go:Install/Update tools,安装go语言工具包

img

编写一个简单的go程序检验VSCode下的go运行环境是否配置成功

package main

import "fmt"

func main() {
    fmt.Println("Hello go")
}

// 运行结果
// Hello go

3.编写menu项目

在GitHub上创建一个仓库,用于保存实验代码

img

把仓库克隆到本地(提前配置好ssh)

git clone git@github.com:ZhouDongdl/se_menu.git

新建文件menu.go,编写实验代码

package main

import (
    "fmt"
    "os"
    "strings"
)

func main() {
    var cmd string
    for true {
        fmt.Printf("Please enter your command:\n")
        fmt.Scanln(&cmd)
        if strings.EqualFold(cmd, "help") {
            fmt.Println("This is help cmd")
        } else if strings.EqualFold(cmd, "quit") {
            os.Exit(0)
        } else {
            fmt.Println("Wrong cmd!")
        }
    }
}

运行menu.go

$ go run menu.go
Please enter your command:
help
This is help cmd
Please enter your command:
exit
Wrong cmd!
Please enter your command:
quit

更新仓库

$ git add menu.go 
$ git commit -m "first menu"
$ git push

img

参考资料:

Go语言圣经
Go语言教程 | 菜鸟教程

作者:518

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

567

社区成员

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

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