1、Go+简介💬
🔍 Go+ 是七牛云 CEO 许式伟发明的一门可用于工程、STEM 教育和数据科学的编程语言,于 2020 年 7 月正式发布,2021 年 10 月推出 1.0 版本。
2、Go+特点💎
📣 Go+ Slogan:“The Go+ language for engineering, STEM education, and data science”
🔔 Go+ 是目前第一个顺应“三位一体”发展潮流的编程语言,同时兼顾工程、STEM 教育、数据科学三大领域
🏆 for engineering:致力于让工程师可以使用简洁、容易掌握的语言去工作,这在纷繁复杂的工程技术领域是非常重要的进化;
🏆🥇 for STEM education:Go+ 简单易学,非常适合作为青少年学习编程的入门语言,且能在未来的工作中的延续使用,无需切换语言;
🏆 for data science:目标是让工程师和数据科学家可以用相同的语言去对话,这在以数据驱动创新的未来尤为重要。
3、Go+优势🏆
Go+ 有三大优势🌈:更简单,更强大,兼容性强。其中:
📕语法更加简单、优雅。在继承 Go 语言特性最小化的优势和工程理念的基础上,Go+ 更接近自然语言,有理数更贴近数学的表达方式;
📗低代码化,去复杂性。入门门槛较低,入门使用时屏蔽了工程化的复杂性;
📘性能强大。强化每行代码的能力,完成功能所需的代码量更少;
三、🔑Go+安装与配置
🎈 目前,建议通过源码安装 Go+。安装下载命令如下💨🕞
git clone https://github.com/goplus/gop.git cd gop # On mac/linux run: ./all.bash # On Windows run: all.bat 💡:实际上, all.bash 和 all.bat 内部都会执行 go run cmd/install.go
(1)下载并上传二进制包📘
下载二进制包:go1.17.4.linux-amd64.tar.gz
这里采用源码安装方法
🛒还有其他版本的二进制包可供选择下载,满足不同环境使用。
💖将下载的go1.17.4.linux-amd64.tar.gz
压缩包上传至CentOS服务器中
(2)将二进制包解压至 /usr/local目录📙
执行下列命令
tar -C /usr/local -zxvf go1.17.4.linux-amd64.tar.gz
(3)将 /usr/local/go/bin 目录添加至PATH环境变量📕
export PATH=$PATH:/usr/local/go/bin
(4)验证Go环境是否配置成功📘
执行go version
命令
[root@centos ~]# go version go version go1.17.4 linux/amd64
(5)创建go程序测试Go编程环境📗
[root@centos ~]# vim hello.go [root@centos ~]# cat hello.go package main import "fmt" func main() { fmt.Println("Hello, World!") } [root@centos ~]# go run hello.go Hello, World! [root@centos ~]# ll total 131660 -rw-------. 1 root root 1531 Nov 28 17:50 anaconda-ks.cfg drwxr-xr-x 3 root root 17 Dec 5 19:11 go -rw-r--r-- 1 root root 134807371 Dec 5 19:04 go1.17.4.linux-amd64.tar.gz drwxr-xr-x 17 root root 4096 Dec 5 19:27 gop -rw-r--r-- 1 root root 74 Dec 5 20:16 hello.go [root@centos ~]#
正式安装🔊
2、🌈 拷贝 Git 仓库到本地
若出现以下报错信息❌❗
[root@ecs-kunpeng GO+]# git clone https://github.com/goplus/gop.git -bash: git: command not found
则通过下列命令安装git即🉑
# ✅ 通过yum查看提供的Git组件版本 [root@ecs-kunpeng GO+]# yum provides git git-2.27.0-1.el8.aarch64 : Fast Version Control System Repo : AppStream Matched from: Provide : git = 2.27.0-1.el8 # ✅ 通过yum源安装Git组件 [root@ecs-kunpeng GO+]# yum install -y git-2.27.0-1.el8.aarch64 CentOS-8 - AppStream 54 kB/s | 4.3 kB 00:00 CentOS-8 - Base 43 kB/s | 3.9 kB 00:00 CentOS-8 - Extras 19 kB/s | 1.5 kB 00:00 Extra Packages for Enterprise Linux Modular 8 - aarch64 34 kB/s | 3.0 kB 00:00 Extra Packages for Enterprise Linux 8 - aarch64 51 kB/s | 4.7 kB 00:00 Dependencies resolved. ======================================================================================================================== Package Architecture Version Repository Size ======================================================================================================================== Installing: git aarch64 2.27.0-1.el8 AppStream 164 k Installing dependencies: git-core aarch64 2.27.0-1.el8 AppStream 5.6 M git-core-doc noarch 2.27.0-1.el8 AppStream 2.5 M perl-Digest noarch 1.17-395.el8 AppStream 27 k perl-Digest-MD5 aarch64 2.55-396.el8 AppStream 37 k ......中间安装步骤省略...... perl-parent-1:0.237-1.el8.noarch perl-podlators-4.11-1.el8.noarch perl-threads-1:2.21-2.el8.aarch64 perl-threads-shared-1.58-2.el8.aarch64 Complete! [root@centos]#
🔔 通过源码安装 Go+
[root@centos]# git clone https://github.com/goplus/gop.git ne https://github.com/goplus/gop.gitCloning into 'gop'... remote: Enumerating objects: 16502, done. remote: Counting objects: 100% (4784/4784), done. remote: Compressing objects: 100% (1519/1519), done. remote: Total 16502 (delta 3078), reused 4567 (delta 2936), pack-reused 11718 Receiving objects: 100% (16502/16502), 20.62 MiB | 147.00 KiB/s, done. Resolving deltas: 100% (9600/9600), done.
🔍 查看获取的Git服务组件
[root@centos]# ll total 4 drwxr-xr-x 15 root root 4096 Dec 2 23:43 gop [root@centos]# cd gop/ [root@ecentos]# ll total 120 -rwxr-xr-x 1 root root 698 Dec 2 23:43 all.bash -rw-r--r-- 1 root root 41 Dec 2 23:43 all.bat drwxr-xr-x 4 root root 4096 Dec 2 23:43 ast drwxr-xr-x 2 root root 4096 Dec 2 23:43 builtin drwxr-xr-x 3 root root 4096 Dec 2 23:43 cl drwxr-xr-x 8 root root 4096 Dec 2 23:43 cmd -rw-r--r-- 1 root root 654 Dec 2 23:43 dummy.go drwxr-xr-x 2 root root 4096 Dec 2 23:43 env drwxr-xr-x 2 root root 4096 Dec 2 23:43 format -rw-r--r-- 1 root root 161 Dec 2 23:43 go.mod -rw-r--r-- 1 root root 3105 Dec 2 23:43 go.sum -rw-r--r-- 1 root root 11353 Dec 2 23:43 LICENSE -rwxr-xr-x 1 root root 698 Dec 2 23:43 make.bash -rw-r--r-- 1 root root 41 Dec 2 23:43 make.bat -rw-r--r-- 1 root root 1769 Dec 2 23:43 Makefile drwxr-xr-x 4 root root 4096 Dec 2 23:43 parser drwxr-xr-x 3 root root 4096 Dec 2 23:43 printer -rw-r--r-- 1 root root 13702 Dec 2 23:43 README.md -rw-r--r-- 1 root root 14088 Dec 2 23:43 README_zh.md drwxr-xr-x 2 root root 4096 Dec 2 23:43 scanner drwxr-xr-x 2 root root 4096 Dec 2 23:43 token drwxr-xr-x 5 root root 4096 Dec 2 23:43 x [root@ecs-kunpeng gop]#
3、📚 执行./all.bash命令安装Go+
若出现以下报错信息❌❗
[root@centos gop]# ./all.bash + go run cmd/make.go --install --autoproxy go: finding github.com/qiniu/x v1.11.5 go: finding github.com/goplus/gox v1.8.0 go: golang.org/x/tools@v0.1.7: unrecognized import path "golang.org/x/tools" (https fetch: Get https://golang.org/x/tools?go-get=1: dial tcp 142.251.42.241:443: i/o timeout) go: golang.org/x/mod@v0.5.1: unrecognized import path "golang.org/x/mod" (https fetch: Get https://golang.org/x/mod?go-get=1: dial tcp 1 42.251.42.241:443: i/o timeout) go: github.com/goplus/gox@v1.8.0: unknown revision v1.8.0 go: github.com/qiniu/x@v1.11.5: unknown revision v1.11.5 go: error loading module requirements
则先配置 GOPROXY 环境变量,或者可以直接挂梯子访问,再安装。
参考链接🔗:https://goproxy.io/zh/
[root@centos gop]# ./all.bash + go run cmd/make.go --install --autoproxy Installing Go+ tools... go: downloading github.com/goplus/gox v1.8.0 go: downloading github.com/qiniu/x v1.11.5 go: downloading golang.org/x/mod v0.5.1 go: downloading golang.org/x/tools v0.1.7 go: downloading golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 go: downloading golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e github.com/goplus/gop/token github.com/goplus/gop/scanner github.com/goplus/gop/ast github.com/goplus/gop/env github.com/qiniu/x/log github.com/goplus/gop/parser github.com/goplus/gop/x/mod/internal/lazyregexp golang.org/x/mod/internal/lazyregexp golang.org/x/mod/semver golang.org/x/xerrors/internal golang.org/x/xerrors golang.org/x/mod/module github.com/goplus/gop/x/mod/modfile github.com/goplus/gox/internal github.com/goplus/gox/internal/go/printer github.com/goplus/gox/internal/go/format golang.org/x/mod/modfile golang.org/x/sys/execabs golang.org/x/tools/internal/typeparams golang.org/x/tools/go/internal/gcimporter golang.org/x/tools/go/gcexportdata golang.org/x/tools/internal/event/label golang.org/x/tools/internal/event/keys golang.org/x/tools/internal/event/core golang.org/x/tools/internal/event golang.org/x/tools/internal/gocommand golang.org/x/tools/go/internal/packagesdriver golang.org/x/tools/internal/packagesinternal golang.org/x/tools/internal/typesinternal golang.org/x/tools/go/packages golang.org/x/tools/go/ast/astutil golang.org/x/tools/go/types/typeutil github.com/goplus/gox github.com/goplus/gop/cl github.com/goplus/gop/cmd/gengo github.com/goplus/gop/cmd/internal/base github.com/goplus/gop/cmd/internal/search github.com/goplus/gop/x/mod/modfetch github.com/goplus/gop/cmd/internal/modload github.com/goplus/gop/cmd/internal/build github.com/goplus/gop/cmd/internal/clean github.com/goplus/gop/cmd/internal/env github.com/goplus/gop/cmd/internal/gengo github.com/goplus/gop/printer github.com/goplus/gop/format github.com/goplus/gop/x/format github.com/goplus/gop/cmd/internal/gopfmt github.com/goplus/gop/cmd/internal/help github.com/goplus/gop/cmd/internal/install github.com/goplus/gop/cmd/internal/mod github.com/goplus/gop/x/gopmod github.com/goplus/gop/cmd/internal/run github.com/goplus/gop/cmd/internal/test github.com/goplus/gop/cmd/internal/version github.com/goplus/gop/cmd/gop github.com/goplus/gop/cmd/gopfmt github.com/goplus/gop/cmd/goprun github.com/goplus/gop/cmd/goptestgo Go+ tools installed successfully! NEXT STEP: We just installed Go+ into the directory: /root/gop/bin To setup a better Go+ development environment, we recommend you add the above install directory into your PATH environment variable. [root@centos gop]#
当提示Go+ tools installed successfully!
时,说明Go+安装完成。
若出现以下报错信息❌❗
[root@centos bin]# ./gop run hello.go [FATAL] /root/gop/cmd/internal/run/mod.go:58: exec: "go": executable file not found in $PATH [root@centos bin]#
4、📍 验证Go+环境是否安装成功
进入/root/gop/bin/
目录下,查看配置文件
执行./gop version
命令,查看版本信息
[root@centos ~]# cd /root/gop/bin/ [root@centos bin]# ll total 22172 -rwxr-xr-x 1 root root 9602677 Dec 5 19:12 gop -rwxr-xr-x 1 root root 2832697 Dec 5 19:12 gopfmt -rwxr-xr-x 1 root root 7840399 Dec 5 19:12 goprun -rwxr-xr-x 1 root root 2412593 Dec 5 19:12 goptestgo -rw-r--r-- 1 root root 73 Dec 5 19:26 hello.go [root@centos bin]# [root@centos bin]# ./gop version gop v1.0.32-61-g15116b6 linux/amd64
5、✅ 创建go+程序测试Go+编程环境
[root@centos bin]# pwd /root/gop/bin [root@centos bin]# vim hello.go [root@centos bin]# cat hello.go package main import "fmt" func main() { fmt.Println("Hello World!\n") fmt.Println("My name is xybDIY.") } [root@centos bin]# ./gop run hello.go Hello World! My name is xybDIY. [root@centos bin]#
四、🎨总结
🎈🎈本文是在Linux系统环境下(基于CentOS系统进行操作)完成Go+环境搭建和实现程序代码运行的,相对来说操作过程比较简单,执行./all.bash
,即可完成安装,不过在此之前需要完成好Go环境的安装。 🏆🏆