0%

go mod 的使用

1
2
3
4
5
6
7
8
# xxx表示项目的根域名
go mod init "xxx"
# 映射
go mod edit -replace=golang.org/x/sys@v0.0.0=github.com/golang/sys@v0.0.0
# 执行以下命令会自动分析项目里的依赖关系同步到go.mod文件中,同时创建go.sum文件
go mod tidy
# 直接使用这个命令就可以把GOPATH/src目录下的依赖包同步到当前项目目录中
go mod vendor

设置国内源

1
2
export GOPROXY=https://goproxy.io
export GOPROXY=https://mirrors.aliyun.com/goproxy/

go 可能需要用到的环境变量

1
2
3
4
5
6
export GOROOT=/usr/local/go
export GOARCH=amd64
export GOPATH=/usr/local/gopath
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOPATH/bin
export GOBIN=/home/linuxbrew/.linuxbrew/bin/

开启或关闭go mod

1
2
3
4
export GO111MODULE=auto
#auto 自动
#on 使用mod
#off 不使用mod

go类型转换

转载:https://www.jb51.net/article/119164.htm

int转string

1
2
s := strconv.Itoa(i)
s := strconv.FormatInt(int64(i), 10)

int64转string

1
2
i := int64(123)
s := strconv.FormatInt(i, 10)

string转int

1
i, err := strconv.Atoi(s))

string转int64

1
i, err := strconv.ParseInt(s, 10, 64)

go 字符串操作

转载:https://blog.csdn.net/li_101357/article/details/80241224

1
2
3
4
5
6
# 子串substr在s中,返回true
func Contains(s, substr string) bool
# chars中任何一个Unicode代码点在s中,返回true
func ContainsAny(s, chars string) bool
# Unicode代码点rs中,返回true
func ContainsRune(s string, r rune) bool

电子书

《Effective Go》中英双语版

1
2
3
4
5
pip install virtualenv
pip install virtualenvwrapper
pip install virtualenvwrapper-win
mkvirtualenv XXX
deactivate

git 代理设置

1
2
3
4
git config --global http.proxy 'http://127.0.0.1:1087'
git config --global https.proxy 'http://127.0.0.1:1087'
git config --global http.proxy 'socks5://127.0.0.1:1086'
git config --global https.proxy 'socks5://127.0.0.1:1086'

git取消代理

1
2
git config --global --unset http.proxy
git config --global --unset https.proxy

git查看代理

方法一
1
cat ~/.gitconfig
方法二
1
git config --global http.proxy

删除git已缓存的文件夹:

1
2
git rm --cached "文件路径"
git rm -r --cached .vscode/

设置git的默认编辑器为vim:

1
git config --global core.editor vim

注释填写错误重填命令:

1
git commi --amend

merge合并到主分支的正确方式

1
git merge --no-ff feat-homepage

删除本地分支

1
git branch -d

git提交规范

https://www.yuque.com/fe9/basic

type 是用于说明该 commit 的类型的,一般我们会规定 type 的类型如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
feat: 新功能(feature)<br>
fix: 修复 bug<br>
docs: 文档(documents)<br>
style: 代码格式(不影响代码运行的格式变动,注意不是指 CSS 的修改)<br>
refactor: 重构(既不是新增功能,也不是修改 bug 的代码变动)<br>
test: 提交测试代码(单元测试,集成测试等)<br>
chore: 构建或辅助工具的变动<br>
misc: 一些未归类或不知道将它归类到什么方面的提交<br>
scope。scope 说明 commit 影响的范围,比如数据层,控制层,视图层等等,这个需要视具体场景与项目的不同而灵活变动<br>
subject。subject 是对于该 commit 目的的简短描述<br>
使用第一人称现在时的动词开头,比如 modify 而不是 modified 或 modifies<br>
首字母小写,并且结尾不加句号<br>
ISSUEE_ID。这个与公司的需求管理与项目管理有关,假设你的项目放在 github 上,你的需求或者 bug 修复可能会有对应的 issues 记录,你可以加到你的 commit 信息中如 issue-37938634。<br>

强制将两个不相干的仓库合并

1
git pull origin master --allow-unrelated-histories

分支开发策略

分支管理-廖雪峰

强制覆盖远程分支

1
git push origin 分支名 —force

测试ssh_key是否有效

1
ssh -T git@github.com

git未知

1
git的unshallow和--depth=1

提交指定文件夹下的所有文件到指定分支

git subtree push —prefix=dist origin gh-pages
git subtree push —prefix=dist git@github.com:htongxxx/xxxx.git gh-pages
git push using: git@github.com:htongxxxxx/xxxx.git gh-pages

根据端口杀进程

1
2
lsof -i:8080
kill -9 42624

grep 筛选参数

1
2
ps -aux | grep mysql
ls -l bin | grep mysql #查看二进制的软链接

后台运行

1
nohup command > myout.file 2>&1 &

查看shell bash

1
cat /etc/shells

切换shell环境

1
emulate bash

alias

1
alias runphp="php -t restful/ -S localhost:8000"

查看进程的程序路径

1
netstat -nlp

显示最后登录的终端

1
last

改变文件夹权限

1
sudo chown -R $(whoami) testapp

查找包含”xxx”文件名的文件

1
2
find ~ -iname  "xxxx"
find / -name 'scrapyd-deploy' //全局搜索文件

软链接 ln

1
2
3
4
5
6
7
sudo ln -s /opt/node-v6.9.5-linux-x64/bin/cnpm  /usr/local/bin/cnpm
//生成软连接
ln -s /mnt/d/code .
//正确的删除方式(删除软链接,但不删除实际数据)
rm -rf ./test_chk_ln
//错误的删除方式,(这样就会把原来test_chk下的内容删除)
rm -rf ./test_chk_ln/

tar.gz压缩解压说明

1
2
3
4
5
6
7
8
//解压:
tar zxvf filename.tar.gz
//压缩:
tar zcvf filename.tar.gz dirname
//z:通过gzip支持压缩或解压缩。还有其他的压缩或解压缩方式,比如j表示bzip2的方式。
//x:解压缩。c是压缩。
//v:在压缩或解压缩过程中显示正在处理的文件名
//f:f后面必须跟上要处理的文件名。

将文件夹压缩到zip中,并排除指定文件夹

1
zip -r 12306.zip 12306/ -x 12306/venv/* -x 12306/ticket/* -x "cloud_backweb/download/wordfile/*"

给二进制赋值执行权限

1
chmod +x gitea

获取指定文件夹的大小

1
du -sh market | sort -n

查看当前目录下各文件大小

1
du -h --max-depth=1

查找进程中包含“xxxx”的多个pid

1
2
ps -ef|grep "xxxx"|grep -v grep|cut -c 9-15
ps -ef | grep "xxxx" | grep -v grep | awk '{print $2}'

查找包含“xxx”的进程并杀死

1
2
ps -ef|grep "xxx"|grep -v grep|cut -c 9-15|xargs kill -9
# 转载地址:https://www.cnblogs.com/joshua317/p/9235811.html

apt-get 相关命令

1
2
apt-get remove xxx //会删除软件包而保留软件的配置文件
apt-get purge xxx //会同时清除软件包和软件的配置文件

zsh

1
2
3
export PATH=$HOME/bin:/usr/local/bin:$PATH:/home/htongtongx/.local/bin
export GOBIN=/home/linuxbrew/.linuxbrew/bin/
export PATH=$PATH:$GOPATH/bin

在ubuntu14.04下python3.4升级3.6

when update python3.4 to python3.6 on ubuntu 14.04. The following solved me:

1
wget https://bootstrap.pypa.io/ez_setup.py -O - | python3

linux配置文件加载顺序

1
2
3
4
5
/etc/profile
/etc/environment
~/.bash_profile
~/.bashrc
/etc/bashrc

查看 history 最后 5 条命令:

1
2
3
4
5
6
# history | tail -5
10068 hexo new "history of linux"
10069 export HISTTIMEFORMAT='%F %T '
10070 history
10071 history | more
10072 history | tail 5

执行 history 第 10072 条命令:

1
# !10072

参考:

History(历史)命令用法 15 例
Linux history 命令小结

centos下安装nginx

1
2
3
rpm -ivh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm
yum install -y nginx
/usr/sbin/nginx -s reload

查看进程并kill掉

1
2
ps -ef | grep nginx
kill -9 xxxx

centos下安装supervisor

1
2
3
4
5
6
7
8
9
yum install epel-release
yum install -y supervisor
systemctl enable supervisord # 开机自启动
systemctl start supervisord # 启动supervisord服务
systemctl status supervisord # 查看supervisord服务状态
ps -ef|grep supervisord # 查看是否存在supervisord进程
supervisorctl status 查看进程状态
supervisorctl reload 重启supervisord
supervisorctl start|stop|restart 启动关闭重启进程

docker 进入容器终端:

1
2
docker exec -it container_name bash
docker exec -it 638b10223b73 /bin/bash

docker 查询资源占用:

1
docker stats

你想要输入的替代文字

查看docker日志输出

1
sudo docker logs -f -t —tail 行数 容器名

进入容器

1
docker exec -it 638b10223b73  /bin/bash

新建一个docker容器

1
docker run --restart=always --name=abc -e PASSWORD=我是密码 -e METHOD=aes-128-ctr -p 6743:8388 -p 6743:8388/udp -d abcabc/abcabc-libev

好文章

docker-cheat-sheet

docker-compose 的mysql主从docker

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
version: "3"

services:
mysql-master:
image: mysql:8.0.18
environment:
MYSQL_ROOT_PASSWORD: "xxxxx"
volumes:
- /home/mysql-master/data:/var/lib/mysql
- ./contrib/mysql/master.cnf:/etc/my.cnf
ports:
- 3307:3306
restart: always
privileged: true
networks:
default:
aliases:
- mysql-master
mysql-slave:
image: mysql:8.0.18
environment:
MYSQL_ROOT_PASSWORD: "xxxxx"
volumes:
- /mnt/mysql-slave/data:/var/lib/mysql
- ./contrib/mysql/slave.cnf:/etc/my.cnf
ports:
- 3308:3306
restart: always
networks:
default:
aliases:
- mysql-slave

ubuntu nginx 服务取消开机启动:

1
update-rc.d -f nginx remove

nginx 服务开启开机启动:

1
update-rc.d –f nginx defaults

nginx 服务启动\重启\停止:

1
sudo /etc/init.d/nginx start\restart\stop

nginx 服务器开启自启动

1
systemctl enable nginx

nginx 命令

1
2
3
4
systemctl start nginx.service
systemctl stop nginx.service
systemctl reload nginx.service
systemctl status nginx.service

反向代理

1
2
3
4
5
6
7
location /v1/ai/{
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header HOST $http_host;
proxy_set_header X-NginX-Proxy true;
proxy_pass http://127.0.0.1:9030;
proxy_redirect off;
}

Git clone 时发生“error: index-pack died of signal 9”错误

1
检查是否内存不够