使用Go语言编写Menu

木子@林夕 2023-03-18 21:22:21

1.实验目的

选用go或rust编写menu项目,创建一个版本库(gitee或github),采用VS Code作为编译调试环境。撰写一个帖子,从创建版本库、配置VS Code编译调试环境、编写menu第一版简单程序,以及最终调试运行,完整记录下来,目标是为go或rust的开发者提供一个开发环境配置和工作流程的参考。

2.实验过程

2.1 创建版本库

img

2.2 配置相关环境

go官网下载地址:https://golang.google.cn/dl/

img

选择最新的Windows版本进行下载。直接解压缩到相应的文件夹即可。

配置GOROOT系统变量:也就是解压缩到的文件夹。

img

配置GOPATH系统变量:

img

最后配置bin环境变量:在系统变量Path中新建

img

检查是否成功安装Go环境:显示版本信息即配置成功。

img

配置Go代理的环境变量

使用下面的命令:

go env -w GO111MODULE=on  Golang1.16默认开启,1.16一下需要执行这条命令
go env -w GOPROXY=https://goproxy.cn,direct 

img

2.3 VScode配置Go环境

安装Go语言插件

img

2.4 编写Menu.go程序

package main

import "fmt"

func main() {
    for {
        var commands string
        var tip1 string = "Say Hello"
        var tip2 string = "You quitted this program"
        var tip3 string = "The command list is as follows:"
        var cmd1 string = "cmd:HELPME"
        var cmd2 string = "cmd:HELLO"
        var cmd3 string = "cmd:QUIT"
        fmt.Printf("input:")
        fmt.Scanln(&commands)
        if commands == "HELPME" {
            fmt.Printf("命令列表:%s\n", tip3)
            fmt.Printf("命令1%s\n", cmd1)
            fmt.Printf("命令2%s\n", cmd2)
            fmt.Printf("命令3%s\n", cmd3)

        } else if commands == "HELLO" {
            fmt.Printf("提示:%s\n", tip1)
        } else if commands == "QUIT" {
            fmt.Printf("提示:%s\n", tip2)
            break
        } else {
            fmt.Println("Please try \"HELPME\" command to find the solution!")
        }
    }
}

调试运行结果如下:

img

2.5 Gitee版本控制

初始化本地仓库:直接点,或者在终端输入git init

img

接下来就是添加到暂存区以及提交到本地仓库:

git add .
git commit -m "The first version of Menu"

关联远程仓库

git remote add origin https://gitee.com/mzlxplus/menu.git

(使用git remote查看关联远程仓库情况)

如果初始化了Redame文件,则要处理冲突:

一是直接强制推送:

git push -f -u origin master


二是使用

git pull origin master --allow-unrelated-histories

先拉取,然后再push

这里采用第二种方式,然后再看就会发现多了两个README文件

推送到远程仓库:

git push -u origin master


查看Gitee上的远程仓库:

img

学号后三位:229

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

566

社区成员

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

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