分享

实习第一周(golang)

 大前端之旅 2021-12-16
  • 一,序

  • 二,基础学习

  • 三,环境安装

  • 四,项目操练

    • GO111MODULE

  • 五,此外附上我用过的一些资料

一,序

2020年8月3我来实习了,试想一个Java都还没学会熟练使用的人,却要用golang去重新做项目,我能退缩吗,当然不能,于是我用一周的时间来熟悉golang,

二,基础学习

于是我对基础的数据类型,指针,运算符,程序流程控制,函数,包,错误处理,数组,切片,map,结构体,方法,封装继承接口

以及多态,文件操作,以及JSON序列化反序列化,单元测试,进程,线程,反射,管道,socket编程,redis,等有了初步了解,是不是现在就成功了,肿么可能,我要立马上线,去拿项目读源码学习,于是开始了我的配置环境阶段

三,环境安装

我安装的是最新的go版本1.14,下载的是go1.14.windows-amd64.msi 安装文件。文件需要到https:/// 去下载。由于众所周知的原因,需要翻墙,否则网站打不开。

image-20200810124757635

安装很顺利。安装完后打开一个cmd窗口,输入:

E:\goproject>go versiongo version go1.14.6 windows/amd64

说明已经安装成功。

四,项目操练

想着到github上找一个go语言编写的项目弄到本地查看编译下。找到一个bee,beego在如何获取地方看到:

go get github.com/astaxie/beego

这是要在cmd 窗口直接输入这行命令就能获取。我于是试了下。可是,输入命令后看着是在运行,但是运行结束后,报以下提示信息,

原来是代理的问题,

unrecognized import path "/x/text/transform": https fetch: Get "https:///x/text/transform?go-get=1": dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respondafter a period of time, or established connection failed because connected host has failed to respond.unrecognized import path "/x/text/unicode/norm": https fetch: Get "https:///x/text/unicode/norm?go-get=1": dial tcp 216.239.37.1:443: connectex: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.# cd .; git clone -- https://github.com/gadelkareem/delve C:\Users\luckly\go\src\github.com\gadelkareem\delveCloning into 'C:\Users\luckly\go\src\github.com\gadelkareem\delve'...error: RPC failed; curl 56 OpenSSL SSL_read: SSL_ERROR_SYSCALL, errno 104fatal: the remote end hung up unexpectedlyfatal: early EOFfatal: index-pack failedpackage github.com/gadelkareem/delve/pkg/terminal: exit status 128package github.com/gadelkareem/delve/service: cannot find package "github.com/gadelkareem/delve/service" in any of: F:\sofaware\GO\src\github.com\gadelkareem\delve\service (from $GOROOT) C:\Users\luckly\go\src\github.com\gadelkareem\delve\service (from $GOPATH)package github.com/gadelkareem/delve/service/debugger: cannot find package "github.com/gadelkareem/delve/service/debugger" in any of: F:\sofaware\GO\src\github.com\gadelkareem\delve\service\debugger (from $GOROOT) C:\Users\luckly\go\src\github.com\gadelkareem\delve\service\debugger (from $GOPATH)package github.com/gadelkareem/delve/service/rpc2: cannot find package "github.com/gadelkareem/delve/service/rpc2" in any of: F:\sofaware\GO\src\github.com\gadelkareem\delve\service\rpc2 (from $GOROOT) C:\Users\luckly\go\src\github.com\gadelkareem\delve\service\rpc2 (from $GOPATH)package github.com/gadelkareem/delve/service/rpccommon: cannot find package "github.com/gadelkareem/delve/service/rpccommon" in any of: F:\sofaware\GO\src\github.com\gadelkareem\delve\service\rpccommon (from $GOROOT) C:\Users\luckly\go\src\github.com\gadelkareem\delve\service\rpccommon (from $GOPATH)# cd C:\Users\luckly\go\src\github.com\astaxie\beego; git pull --ff-onlyfatal: not a git repository (or any parent up to mount point /cygdrive)Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).package github.com/astaxie/beego/swagger: exit status 128package github.com/astaxie/beego/utils: cannot find package "github.com/astaxie/beego/utils" in any of: F:\sofaware\GO\src\github.com\astaxie\beego\utils (from $GOROOT) C:\Users\luckly\go\src\github.com\astaxie\beego\utils (from $GOPATH)
image-20200810125234917

于是我发挥了爱学习,爱搜索,爱询问的能力,了解到了有代理这回事,使用go.mod来进行包管理

GO111MODULE

GO111MODULE有三个值:off, onauto(默认值)

  • GO111MODULE=off,go命令行将不会支持module功能,寻找依赖包的方式将会沿用旧版本那种通过vendor目录或者GOPATH模式来查找。

  • GO111MODULE=on,go命令行会使用modules,而一点也不会去GOPATH目录下查找。

    GO111MODULE=auto

    ,默认值,go命令行将会根据当前目录来决定是否启用module功能。这种情况下可以分为两种情形:

    • 当前目录在GOPATH/src之外且该目录包含go.mod文件
    • 当前文件在包含go.mod文件的目录下面。

那么我们就来设置吧,我打开命令行:

C:\Users\luckly>go env -w GO111MODULE=on
C:\Users\luckly>go env -w GOPROXY=https://,direct

并进行了简单测试,新建一个名为 main.go的项目,项目路径 e:\goproject (注意,该路径并不在GOPATH里)

image-20200810131549241

当我再次打开命令行的时候

C:\Users\luckly>go get github.com/beego/beego: downloading github.com/beego/bee v1.12.0go: github.com/beego/bee upgrade => v1.12.0go: downloading github.com/gorilla/websocket v1.4.2go: downloading github.com/astaxie/beego v1.12.1go: downloading github.com/lib/pq v1.7.0go: downloading github.com/go-sql-driver/mysql v1.5.0go: downloading github.com/gadelkareem/delve v1.4.2-0.20200619175259-dcd0133go: downloading github.com/smartwalle/pongo2render v1.0.1go: downloading gopkg.in/yaml.v2 v2.3.0go: downloading github.com/pelletier/go-toml v1.2.0go: downloading github.com/davecgh/go-spew v1.1.1go: downloading github.com/fsnotify/fsnotify v1.4.9go: downloading github.com/flosch/pongo2 v0.0.0-20200529170236-5abacdfa4915go: downloading /x/sys v0.0.0-20191005200804-aed5e4c7ecf9go: downloading github.com/spf13/viper v1.7.0go: downloading github.com/hashicorp/hcl v1.0.0go: downloading github.com/spf13/pflag v1.0.3go: downloading github.com/mitchellh/mapstructure v1.1.2go: downloading github.com/spf13/jwalterweatherman v1.0.0go: downloading gopkg.in/ini.v1 v1.51.0go: downloading github.com/spf13/cast v1.3.0go: downloading github.com/magiconair/properties v1.8.1go: downloading github.com/subosito/gotenv v1.2.0go: downloading github.com/spf13/afero v1.1.2go: downloading /x/text v0.3.2go: downloading github.com/sirupsen/logrus v1.6.0go: downloading github.com/mattn/go-colorable v0.0.9go: downloading github.com/cosiner/argv v0.1.0go: downloading github.com/mattn/go-isatty v0.0.3go: downloading /x/arch v0.0.0-20190927153633-4e8777c89be4go: downloading github.com/peterh/liner v0.0.0-20170317030525-88609521dc4bgo: downloading github.com/hashicorp/golang-lru v0.5.4go: downloading go.starlark.net v0.0.0-20190702223751-32f345186213go: downloading github.com/konsorten/go-windows-terminal-sequences v1.0.3

竟然成功了,

于是我又紧追其后,在命令行输入了

C:\Users\luckly>beeBee is a Fast and Flexible tool for managing your Beego Web Application.
USAGE bee command [arguments]
AVAILABLE COMMANDS
version Prints the current Bee version migrate Runs database migrations api Creates a Beego API application bale Transforms non-Go files to Go source files fix Fixes your application by making it compatible with newer versions of Beego pro Source code generator dlv Start a debugging session using Delve dockerize Generates a Dockerfile for your Beego application generate Source code generator hprose Creates an RPC application based on Hprose and Beego frameworks new Creates a Beego application pack Compresses a Beego application into a single file rs Run customized scripts run Run the application by starting a local development server server serving static content over HTTP on port
Use bee help [command] for more information about a command.
ADDITIONAL HELP TOPICS

Use bee help [topic] for more information about that topic.

又成功了,至次就成功了吗?没有,为啥?

bee下载到那儿了,不知道,罪过罪过,在我的go语言安装目录的,src ,pkg等下面都没找到,这难道没安上?还是哪里有问题。各种查找。最后终于找到一个解决办法。需要自己创建一个工作区目录。为什么不使用安装目录,是因为要保证安装目录的纯洁性。

打开一看,咋跑C盘去了,仔细一看是自己把代码敲错了,自动添加到C盘了,

image-20200810130117431

我在F盘创建了一个工作目录:F:\software\GO,目录必须是英文,不能有汉字。在这个目录中还要创建3个目录。分别是src,pkg,bin三个目录。并且要在windows系统变量中增加GOPATH,值设置为:F:\software\GO。终于改过来了

image-20200810130357974

然后再打开一个cmd窗口,输入:

go get github.com/beego/bee

执行成功后,可以看到在工作区的src目录下已经有了相应的项目文件。在github.com目录下。

image-20200810130752499

五,此外附上我用过的一些资料

尚硅谷韩顺平Go语言核心编程

redis

一些项目

学习脑图

一些资源

激活goland

Git手册

Golang标准库文档

go学习文档

可以考虑 http://tour. 以及 http://books./gobyexample/

https://www./#

https://www.oschina.net/search?scope=project&q=golang

1.开源项目总结

开源项目

docker

golang

kubernetes

etcd

beego

martini

codis

delve

GO web

beego

GO语框架gin中文中档

以上是我上周的进展,下周继续努力

欢迎继续关注我,后台发送“golamg”获取原文链接及资源

    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多