Home avatar

谷中仁的博客

所有文章观点仅代表本站观点,与他人无关。

Golang 依赖注入 (Dependency Injection)

Dependency Injection 🧪

依赖注入是目前很多优秀框架都在使用的一个设计模式。 Dependency Injection 常常简称为:DI。它是实现控制反转(Inversion of Control – IoC)的一个模式。

在各种大工程中少不了各种测试,其中 TDD 就是非常流行的一种,在前端开发中用的比较多的 Jest 就是一种,在 Golang 开发命令行工具的时候也是需要 DI 这种模式来实现命令行测试的。因为传统的测试室获取不到命令行的输入输出的。

Golang With SQLLite Practice

SQLite 是一个进程内的库,实现了自给自足的、无服务器的、零配置的、事务性的 SQL 数据库引擎。它是一个零配置的数据库,这意味着与其他数据库一样,你不需要在系统中配置。在 Golang 中使用 SQLLite 也相当简单,只需要安装 SQLLite 的 Golang 包即可使用; Golang 就不多介绍了,能看到这个肯定对 Golang 有一定的了解。

Harbor 安装小记

在搭建私有云环境时,我们需要将我们打包的镜像存储在局域网内,而不是把镜像推送到 hub.docker.com;一方面是因为安全问题,另一方面在局域网内存储,网速炒鸡快。当然对于私有云搭建,在本地搭建镜像仓库那是必须的。接下来,对我安装 Harbor 做一个记录。

Go Module 安装不了 golang.org 时的处理方式记录

shell

go: golang.org/x/sys@v0.0.0-20180905080454-ebe1bf3edb33: unrecognized import path "golang.orgnrecognized import path "golang.org/x/sys" (https fetch: G1: dial tcp 216.239.37.1:443: conneet https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.rty did not properly respond after1:443: connectex: A connection attempt failed because the  connected host has failed to respoconnected party did not properly respond after a period of time, or established connection failed because connected : unrecognized import path "golang.host has failed to respond.)
...
go: golang.org/x/crypto@v0.0.0-20180904163835-0709b304e793nected party did not properly respo: unrecognized import path "golang.org/x/crypto" (https fed because connected host has failedtch: Get https://golang.org/x/crypto?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.)
go: error loading module requirements

1 手动加入被墙的包(原始包),一定要记住版本号,实在不知道的话,就试试 v0.0.0;

Go Module 安装不了 golang.org 时的处理方式记录

shell

go: golang.org/x/sys@v0.0.0-20180905080454-ebe1bf3edb33: unrecognized import path "golang.orgnrecognized import path "golang.org/x/sys" (https fetch: G1: dial tcp 216.239.37.1:443: conneet https://golang.org/x/sys?go-get=1: dial tcp 216.239.37.rty did not properly respond after1:443: connectex: A connection attempt failed because the  connected host has failed to respoconnected party did not properly respond after a period of time, or established connection failed because connected : unrecognized import path "golang.host has failed to respond.)
...
go: golang.org/x/crypto@v0.0.0-20180904163835-0709b304e793nected party did not properly respo: unrecognized import path "golang.org/x/crypto" (https fed because connected host has failedtch: Get https://golang.org/x/crypto?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.)
go: error loading module requirements

1 手动加入被墙的包(原始包),一定要记住版本号,实在不知道的话,就试试 v0.0.0;

Npm 安装 git 资源

我们大多数情况下用到的包都是存放在 npmjs.com 这个网站上的,只要我们安装了 Node,我们就可以使用 Node 自带的 npm 包来下载你需要的包;但有时候我们想让我们自己的包或者库私有,哪怎么办呢?很多人就会想到自己搭一个私服,比如 Nexus Repository Manager sinopia; 虽然搭建起来不是很困难,尤其是 sinopia 就是一个 npm 包,安装灰常简单,但是都需要一台服务器,一台服务。.. 一台服。.. 一台。.. 一。..