工作满四年了,过去将近一年时间在凉屋的工作让我产生了极大的转变和技术成长,在进入凉屋之前,我的技术欠缺到了现在的我完全不敢相信的程度,但之前的工作也不是完全浪费时间,所以想记录一下自己工作以来的经历,以后尽可能地将尽可能多的经验转换为决策的依据。
关于在浪潮为什么换工作,是因为浪潮工资太低,周六甚至没有加班费,而加班强度一点也不低,老板“周一来讲讲周六为什么不加班”的言论让人非常不舒服,搬服务器、一根根内存条排查问题也不是一个亟需成长的程序员整天应该做的事情。在觉得自己没有任何留下去的理由后,经过朋友的推荐,去了华为 OD,至于为什么 OD 也去,是因为当时不知道 OD 代表什么,本来就比较佛系,不想在非技术领域探究太多,所以考虑到工资几乎是浪潮y8500块钱的两倍,还能换个领域扩展知识和见识,没有理由不去。现在想想当时如果还留在浪潮,可能还会有很长时间在免费加班做边缘的事情,这种情况是我一定会马上做出改变的。
不过在浪潮工作期间我也学到了很多知识,虽然没有在工作中用到太多,例如从校园走到职场的热情让我啃完了《C和指针》、《Linux应用程序设计》、《UNIX/LINUX shell 编程指南》这几本书,对 linux 应用编程的学习到了华为工作中还在持续发挥重要作用。在写操作系统安装、更新脚本的过程中熟练应用了 shell 编程,从计算机上电、到 BIOS/bootloader 工作、再到 linux 系统的启动流程能略懂一二,能够自己修改操作系统镜像也是一个让极客很满足的技能。
后来到了华为,在华为的第一份工作是消息队列的 demo 开发,用于5G消息,还学习负载均衡的理论知识,因为可能会做负载均衡的服务,但后来真正开始开发,则是5G消息的 MSRP 服务,简单来说就是应用层富文本的解析、转发服务,同时需要关注底层的 TCP + MSRP 协议栈。MSRP 服务的所有数据都存在内存中,包括会话、链路的池子,缓存+顺序处理的 MSRP 包消息队列。华为在将一些虚拟机时代的应用迁移到容器中,但这种迁移并不彻底,在华为有很多被称为大颗粒的服务,实际上就是将原来虚拟机上运行的单体应用打包到了容器中运行,只体现了容器镜像的开发/生产环境一致、快速部
using namespace std;
class Foo {
public:
void foo();
private:
string name;
};
void Foo::foo() {
name = "foo";
cout << name << endl;
}
模板类实现的资源管理类:
template <typename RESTYPE>
class ScopedResource final {
public:
ScopedR
unsigned int num;
bool flag;
std::vector<Customer> list;
Product data;
unsigned int numberOfArticles;
bool isChanged;
std::vector<Custom> customers;
Product orderedProduct;
$ ip addr
...
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
...
$ vi /etc/sysconfig/network-scripts/ifcfg-ens33
...
ONBOOT=yes
BOOTPROTO=static
IPADDR=172.31.18.55
NETMASK=255.255.248.0
GATEWAY=172.31.16.1
$ systemctl restart network
ipconfig /all
可以获取到DNS地址,虚拟机中在/etc/resolv.conf
中配置。
$ cat /etc/resolv.conf
nameserver 116.116.116.116
nameserver 120.80.88.88
$ mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
$ curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
$ sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
$ yum cle
$ sudo passwd root
ipconfig /all
命令查看可以上网的网卡的IP地址、掩码、网关和DNS,在虚拟机中设置:
$ /etc/init.d/network-manager restart
ping www.baidu.com
,能ping通说明网络配置好了。grep 配置的静态IP地址 /etc
可以看到网络的配置文件。
$ apt update # 访问源列表中的每个网址,读取软件列表并缓存
$ apt upgrade # 安装可以更新的软件
dpkg -l | grep ssh
查看SSH有没有安装,默认只安装ssh-client,需要手动安装ssh-server。
apt install ssh-server
systemctl status sshd # 查看SSH服务有没有运行
$ sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup
阿里云开源镜像站:https://developer.aliyun.com/mirror/
ubuntu不同版本名称不同,可通过/etc/lsb-release文件的DISTRIB_CODENAME获取:
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.3 LTS"
$ cat /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubunt
$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
$ yum install docker-ce docker-ce-cli containerd.io
/lib/systemd/system/docker.service:
...
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock
...
$ systemctl deamon-reload
$ systemctl restart docker
FROM golang:1.17
WORKDIR /app
ADD relax /app
COPY static /app/static
COPY conf /app/conf
COPY views /app/views
CMD ["/app/relax"]
docker run -d --name nginx03 -P -v /home/xxx/conf/nginx:/etc/nginx nginx
$ docker run -d --name nginx01 -P -v etc-nginx:/etc/nginx nginx
$ ll /var/lib/docker/volumes/etc-nginx/_data/
总用量 36
drwxr-xr-x 3 root root 4096 2月 13 13:43 ./
drwx-----x 3 root root 4096 2月 13 13:43 ../
drwxr-xr-x 2 root root 4096 2月 13 13:43 conf.d/
-rw-r--r-- 1 root root 1007 12月 28 23:28 fastcgi_params
-rw-r--r-- 1 root root 5349 12月 28 23:28 mime.types
lrwxrwxrwx 1 root root 22 12月 28 23:40 modules -> /usr/lib/nginx/modules
-rw-r--r-- 1 root root 648 12月 28 23:40 nginx.conf
-rw-r--r-- 1 root root 636 12月 28 23:28 scgi_params
-rw-r--r-- 1 root root 664 12月 28 23:28 uwsgi_params
$ docker ps
CONTAINER ID IMAGE COMMAND
> bee new test
// Operations about User
type UserController struct {
beego.Controller
}
// @Title Create user
// @Description Create a user
// @Param body body models.User true "body for user info"
// @Success 200 {int} models.User.Id
// @Failure 403 body id empty
// @router / [POST]
func (u *UserController) Post() {
var user models.User
json.Unmarshal(u.Ctx.Input.RequestBody, &user)
uid := models.AddUser(user)
u.Data["json"] = map[string]string{"uid": uid}
u.ServeJSON()
}
// @APIVersion 1.0.0
// @Title beego Test API
// @Description beego has a cool tool to autogenera
【前言】
Go的工程可以放在两种位置:
一些小伙伴可能长时间使用一种方法,遇到一个新的项目使用了另一种方法,就会不太熟悉,且不熟悉Goland提供了哪些支持,这篇文章介绍两种方法以及在Goland中的相应配置。
【使用GOPATH】
1、配置全局GOPATH环境变量
全局的GOPATH环境变量用于存放下载安装的Go项目代码和二进制文件,执行go install会编译出可执行文件,并拷贝到$GOPATH/bin
目录下;执行go get会将代码下载到$GOPATH/src
目录下,并进行编译和安装,相比go install增加了下载源码步骤。
2、配置项目的“临时”GOPATH
GOPATH下有三个目录:
在全局GOPATH之外创建一个Go的工程,将工程的目录临时添加到GOPATH环境变量中,注意要将工程目录放在GOPATH最前面,Go的编译器等相关工具会按GOPATH的顺序进行搜索,我们要让工程目录的优先级最高,此时go install和go get产生的文件都在工程目录下:
为了能让Goland自动设置我们工程的“临时”GOPATH,可以在这里进行设置:
【使用go mod】
我们使用和上面例子同样的工程,首先删除设置的“临时”GOPATH,可以看到Goland已经不识别工程中的包了:
需要将包的路径改为工程中的绝对路径:
go modules是Go 1.11之后支持的依赖管理方式,我们需要设置一下系统环境变量和Go的环境变量:
set GO111MODULE=auto
go env -w GO111MODULE=auto
go env -w GOPROXY=https://goproxy.cn,https://goproxy.io,direct
GO111MODULE设置为auto是指,在GOPATH下的工程,默认使用旧的GOPATH的管