Go 笔记

安装

下载地址

局域网安装包\\192.168.1.100\nas\exe

Hugo

Hugo,基于 Go 的博客编译器

1
2
3
wget https://github.com/gohugoio/hugo/releases/download/v0.59.0/hugo_extended_0.59.0_Linux-64bit.tar.gz
tar -zxvf ./hugo_0.55.6_Linux-64bit.tar.gz
cp ./hugo /usr/local/bin/

hugo-theme-learn

1
2
3
4
5
6
7
8
9
hugo new site hugo-docs
cd hugo-docs && git init
git submodule add https://github.com/matcornic/hugo-theme-learn.git themes/hugo-theme-learn
cp -a themes/hugo-theme-learn/exampleSite/* .

hugo new --kind chapter basics/_index.md
hugo new basics/first-content.md
hugo new basics/second-content/_index.md
hugo server -D

dot

1
2
3
4
5
6
hugo new site hugo-docs
cd hugo-docs && git init
git submodule add https://github.com/themefisher/dot-hugo-documentation-theme themes/dot
cp -a themes/dot/exampleSite/* .
# vim config.toml [baseURL,themesDir,disableLanguages]
hugo -b http://doc.huizhouyiren.com --cleanDestinationDir --minify

hugo-theme-academic

1
2
3
4
5
6
git clone https://github.com/sourcethemes/academic-kickstart.git My_Website
cd My_Website
git submodule update --init --recursive
xcopy themes\academic\exampleSite\* . /e /Y /d

hugo

Code Server

Code Server,在线版本的 VS Code

安装

1
2
3
4
5
cd /home
wget https://github.com/cdr/code-server/releases/download/1.1156-vsc1.33.1/code-server1.1156-vsc1.33.1-linux-x64.tar.gz
tar -xvf code-server1.1156-vsc1.33.1-linux-x64.tar.gz
mv code-server1.1156-vsc1.33.1-linux-x64 code-server
cd code-server

lib64

code-server 依赖的 C++ 编译器

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16

cd /home

# 此处我的安装路径为 /home/lib64
wget https://adbin.top/packages/lib64.tar.gz
tar -xvf lib64.tar.gz

cd /usr/lib64
cp libstdc++.so.6 libstdc++.so.6.bak
rm libstdc++.so.6

# ln -s (对应路径)/libstdc++.so.6.0.25(对应版本即可,gcc8.2.0带的是libstdc++.so.6.0.25) libstdc++.so.6
ln -s /home/lib64/libstdc++.so.6.0.25 libstdc++.so.6

# 赋予权限
chmod -R 777 ./code-server

启动

1
2
3
4
5
6
7
8

# 启动目录
./code-server /www/wwwroot/a805/front/ --no-auth

https://localhost:8443/

# 字体配置
Consolas, ‘Courier New’, monospace

最新版 code-server

1
2
3
4
5
6
7
curl -fOL https://github.com/cdr/code-server/releases/download/v3.4.1/code-server-3.4.1-amd64.rpm
sudo rpm -i code-server-3.4.1-amd64.rpm
systemctl --user enable --now code-server
# Now visit http://127.0.0.1:8080. Your password is in ~/.config/code-server/config.yaml

code-server --bind-addr 0.0.0.0:8080 --auth none /www/wwwroot/default
code-server --bind-addr 0.0.0.0:8080 --auth password /www/wwwroot/default

gosuv

gosuv,GO语言重写的类supervisor的一个进程管理程序,类似项目有 supervisord

Linux

1
2
3
4
5
6
7
# 安装
curl https://raw.githubusercontent.com/codeskyblue/gosuv/master/get.sh | bash

# 启动
gosuv start-server

http://localhost:11313/

登录验证

vi ~/.gosuv/config.yml

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
server:
  httpauth:
    enabled: true
    username: admin
    password: admin
  addr: :8083
  name: 10.10.99.177
  master: ""
notifications:
  dingtalk:
    groups:
    - secret: c1b8032******************aa736a
      mobile:
      - "153********"
client:
  server_url: http://admin:admin@localhost:8083

重启

gosuv shutdown

1
2
./gogs web
/home/git/gogs/

Windows

nssm

使用 nssm 将 gosuv 注册为服务,参考 natappGogs

1
2
3
4
5
nssm install gogs
nssm start gogs
nssm edit gogs
nssm restart gogs
nssm remove gogs

vbs 开机自启

C:\Users\LJW\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\gosuv.vbs

1
CreateObject("Wscript.Shell").Run "cmd /c """"C:\Users\LJW\ok\exe\gosuv.exe"" ""start-server""""", 0, true

C:\Users\LJW\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\hotel.vbs

1
CreateObject("Wscript.Shell").Run "cmd /c """"C:\Program Files\nodejs\node.exe"" ""C:\Users\LJW\AppData\Local\Yarn\Data\global\node_modules\hotel\lib\daemon"" > ""C:\Users\LJW\.hotel\daemon.log""""", 0, true

运行 Vue 项目

1
2
cd /d D:\WWW\app\775\775-app && quasar dev --port 9775
C:\Windows\System32

gohttpserver

gohttpserver,GO语言HTTP文件服务器

Linux

1
2
3
4
5
6
7
# 安装
tar -zxvf /home/nas/zip/gohttpserver_1.0.5_linux_amd64.zip -C /home/

# 启动
./gohttpserver -r ./ --port 8000 --upload

http://localhost:8000/

Windows

1
2
3
4
cd /d D:\down\go\gohttpserver && gohttpserver -r ../static --port 9090
C:\Windows\System32

http://static.local.laijw.com/

syncthing

Syncthing 是一个开源的同步工具,支持多版本控制,同时支持Windows、Mac OS X、Linux等客户端,和Resilio有点类似

Linux

1
2
3
4
5
6
7
# 安装
tar -zxvf /home/nas/zip/syncthing-linux-amd64-v1.2.2-rc.3.tar.gz -C /home/

# 新建一个用户运行 Syncthing,不要直接以root运行
adduser git
su git
./syncthing

出现 INFO: Detected 0 NAT services 代表启动成功

修改配置文件

1
2
3
4
5
vim /home/git/.config/syncthing/config.xml

# 将 127.0.0.1:8384 改为 0.0.0.0:8384

http://localhost:8384/

开放端口

Syncthing默认监听以下几个端口

1
2
3
4
22000 (TCP)
8384 (TCP)
21027 (UDP)
44647 (UDP)

个人使用只开放 22000 (TCP) 与 8384 (TCP)

8384 是Web访问控制端口 22000 是节点访问端口

Windows

1
2
3
4
cd /d D:\WWW\go\syncthing && syncthing -no-browser
C:\Windows\System32

http://localhost:8384/

webhook

webhook,使用 Go 语言写的 webhook

Linux

1
./webhook -hooks hooks.json -port 9091 -hotreload -verbose

hooks.json

1
2
3
4
5
6
7
8
[
  {
    "id": "test",
    "execute-command": "/home/webhook/redeploy.sh",
    "command-working-directory": "/home/webhook",
    "response-message": "I got the payload!"
  }
]

Windows

1
2
3
4
cd /d D:\down\go\webhook && webhook -hooks hooks.json -port 9091 -hotreload -verbose
C:\Windows\System32

http://webhook.laijw.com/hooks/hugo-docs

hooks.json

 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
[
  {
    "id": "hugo-docs",
    "execute-command": "D:\\down\\go\\webhook\\hugo-docs.bat",
    "command-working-directory": "D:\\down\\go\\webhook",
    "include-command-output-in-response": true,
    "include-command-output-in-response-on-error": true,
    "pass-arguments-to-command": [
      {
        "source": "payload",
        "name": "head_commit.id"
      },
      {
        "source": "payload",
        "name": "pusher.name"
      },
      {
        "source": "payload",
        "name": "pusher.email"
      }
    ],
    "trigger-rule": {
      "and": [
        {
          "match": {
            "type": "payload-hash-sha256",
            "secret": "laijw",
            "parameter": {
              "source": "header",
              "name": "X-Gogs-Signature"
            }
          }
        },
        {
          "match": {
            "type": "value",
            "value": "refs/heads/master",
            "parameter": {
              "source": "payload",
              "name": "ref"
            }
          }
        }
      ]
    }
  }
]

hugo-docs.bat

1
2
3
@echo off

cd /d D:\WWW\go\hugo-docs && hugo

Gogs

Gogs,基于 Go 的 Git 服务器,类似项目有 Gitea

Linux

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
adduser git
su git
cd ~
tar -zxvf /home/nas/zip/gogs_linux_amd64.tar.gz -C /home/git/

# cd /d D:\down\go\gogs && gogs web -port 9095
# C:\Windows\System32
# 数据库选择 sqlite,服务选择离线模式

https://localhost:9095/

模版文件

/home/git/gogs/templates/base

Windows

1
2
3
4
cd /d D:\down\go\gogs && gogs web -port 9095
C:\Windows\System32

https://localhost:9095/

迁移脚本

修改 D:\down\go\gogs\custom\conf\app.ini

1
2
3
[repository]
ROOT = D:/down/go/gogs/gogs-repositories
ENABLE_LOCAL_PATH_MIGRATION = true

gogs.py 放置于用户项目目录下

 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
33
34
35
36
37
#coding=UTF-8
#######coding="utf-8"

import requests
import json
import os
root = os.getcwd()
#本地gogs平台的api地址,目前的api版本是v1
purl = "http://localhost:9096/api/v1"
#gogs 后台设置的root用户token
token = "79a3503f3772f9eb3e1a423860febd218a72e6a9"

#gogs 添加仓库
def Migrate(clone_addr,uid,repo_name):
    url=str(purl)+"/repos/migrate?token="+str(token)
    data1={"clone_addr":str(clone_addr),"uid":str(uid),"repo_name":str(repo_name)}
    res = requests.post(url,proxies=None, data=data1)
    respond = json.loads(res.text)
    return respond       


def getLocalgit():
    file_dir = "./"
    for files in os.listdir(file_dir):
        if(str(files) != "gogs.py"):
            print(files)
            user = "laijw"
            uid = 1
            clone_addr = "D:/down/go/repo/"+ user +"/"+str(files)
            repo_name = str(files).replace(".git","")
            add_result = Migrate(clone_addr,uid,repo_name)
            print(add_result)
try:
    getLocalgit()
except Exception as e:
    print("出错A",e)
    getLocalgit()

执行脚本 python gogs.py

Gitea

Gitee,基于 Go 的 Git 服务器

1
2
3
4
5
6
7
# 使用管理员身份打开 cmd
sc create gitea start= auto binPath= "\"D:\down\go\gitea\gitea.exe\" web -p 9096 --config \"D:\down\go\gitea\custom\conf\app.ini\""

# 删除服务
sc delete gitea

https://localhost:9096/

代码搜索功能

修改 D:\down\go\gitea\custom\conf\app.ini

1
2
[indexer]
REPO_INDEXER_ENABLED = true

迁移本地仓库

修改 D:\down\go\gitea\custom\conf\app.ini

1
2
[security]
IMPORT_LOCAL_PATHS = true

FRP

FRP,内网穿透工具,类似项目有 NPS

1
2
3
4
5
# 服务端启动 frps
./frps -c ./frps.ini

# 客户端启动 frpc
./frpc -c ./frpc.ini

shadowsocks

shadowsocks

config.json

1
2
3
4
5
6
7
8
9
{
    "server":"server ip",
    "server_port":8388,
    "local_port":1080,
    "local_address":"127.0.0.1",
    "password":"123456",
    "method": "aes-128-cfb",
    "timeout":600
}

服务端

防火墙放行 8388 端口

1
./shadowsocks-server -c config.json

客户端

防火墙放行 1080 端口

1
./shadowsocks-local -c config.json

Annie

Annie,视频下载工具

1
2
3
4
5
# 下载文件列表
annie -F list.txt

# 通过 SOCKS5 代理
annie -s 127.0.0.1:1080 -i https://www.youtube.com/watch?v=Gnbch2osEeo

File Browser

File Browser,基于 Go 的开源网盘

1
2
3
4
5
6
tar -zxvf /home/nas/go/linux-amd64-filebrowser.tar.gz -C /home/filebrowser/
cd /home/filebrowser/
./filebrowser -r /home/nas/apk/ -a 0.0.0.0 -p 4000
admin/admin

https://localhost:4000/

bandzip

开源解压软件

1
2
3
4
5
# 压缩
bc a -fmt:zip hello .

# 解压
bc x hello.zip

lefthook

lefthook,基于 Go 的 Git Hook 管理器

1
2
lefthook install
lefthook add pre-commit

lefthook.yml

1
2
3
4
5
6
7
pre-commit:
  commands:
    linter:
      run: yarn -v
  scripts:
    "done.js":
      runner: node

.lefthook\pre-commit\done.js

1
console.log("干的漂亮!!!");

tsocks

1
2
wget https://li.nux.ro/download/nux/misc/el7/x86_64/tsocks-1.8-0.14.beta5.el7.nux.x86_64.rpm
rpm -ivh tsocks-1.8-0.14.beta5.el7.nux.x86_64.rpm

/etc/tsocks.conf

1
2
3
4
5
local = 192.168.0.0/255.255.255.0  #local表示本地的网络,也就是不使用socks代理的网络
local = 127.0.0.0/255.0.0.0
server = 192.168.0.41
server_type = 5
server_port = 1088

Hugo lazy loads

1
<script type="text/javascript" src="https://cdn.bootcss.com/lazysizes/5.2.0/lazysizes.min.js"></script>

{{ .Content }} 替换成下面

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{{ $regex := "(?i)src\\s*=\\s*\"([^\"]*(!|png|jpg|jpeg|gif|bmp|svg))\"" }}
{{ $img := findRE $regex .Content }}

{{ if gt (len $img) 0 }}
  {{ $placeholder := "/image/loading.gif" | relURL }}
  {{ $replacement := print "src=\"" $placeholder "\" data-src=\"$1\" class=\"lazyload\"" }}
  {{ .Content | replaceRE $regex $replacement | safeHTML }}
{{ else }}
  {{ .Content }}
{{ end }}

themes\jane\layouts\partials\scripts.html

1
2
3
4
<link href="https://cdn.bootcss.com/tachyons/4.11.1/tachyons.min.css" rel="stylesheet">
<script type="text/javascript" src="https://cdn.bootcss.com/fuse.js/5.1.0/fuse.min.js"></script>
<script type="text/javascript" src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
<script type="text/javascript" src="{{ "/js/search.js" | relURL }}"></script>

themes\jane\layouts\partials\search_google.html

 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
<!-- Google Search Modal -->
<div class="modal-dialog">
    <!-- Modal content-->
    <div class="modal-content">
      <div id="closeSearch" title="Close" class="close">X</div>
      <div class="modal-header">
        <div class="modal-title">
          {{- if $.Site.Params.search.google.title -}}
            {{ $.Site.Params.search.google.title }}
          {{- else -}}
            搜索
          {{- end -}}
        </div>
      </div>
      <div id="search" class="modal-body pa3">
          <div class="flex flex-row justify-between py2">
            <input id="searchInput" class="w-100 pa2" type="text" v-model="keywords" placeholder="搜索">
          </div>
          <div class="pt3">
            <div v-for="(item,i) in result" :key="i" class="flex flex-column">
              <a class="link underline-hover blue hover-dark-blue f5" :href="location.origin + item.item.url" v-text="item.item.title" target="_blank" rel="noopener noreferrer"></a>
              <p class="f6 ma0 silver hover-gray w-100" v-html="item.item.description"></p>
            </div>
          </div>
      </div>
    </div>
</div>

themes\jane\static\js\search.js

 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
33
34
35
36
37
38
39
$(function () {
  $.getJSON('/feed.json', function (res) {
    var list = res.items;

    var options = {
      isCaseSensitive: false,
      findAllMatches: false,
      includeMatches: false,
      includeScore: false,
      useExtendedSearch: false,
      minMatchCharLength: 1,
      shouldSort: true,
      threshold: 0.5,
      location: 0,
      distance: 100,
      keys: [
        "title",
        "description"
      ]
    }

    var fuse = new Fuse(list, options)

    var App = new Vue({
      el: "#search",
      data() {
        return {
          keywords: ''
        }
      },
      computed: {
        result() {
          return fuse.search(this.keywords)
        }
      }
    })

  })
})

七牛云 qshell

官方文档

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
# 登录
qshell account <Your AccessKey> <Your SecretKey> <Your Name>

# 示例
qshell account aPnFvvdi8OJp0VYF-e1Htul2h5sAm_cWffYGRFmC otP-RZMSSnYyVI0bNmAy99VS1KBLcVZsOEKXf3Mu ty@skysonic.cn

# 上传
qshell fput tyqiniu __UNI__EC2D36D_0425180355.apk __UNI__EC2D36D_0425180355.apk

# 下载链接
http://qiniu.inspirecables.com/__UNI__EC2D36D_0425180355.apk

# 同步文件夹
qshell qupload upload.conf

# 删除空间laijw-book中的所有文件:
qshell listbucket laijw-book -o laijw-book.list.txt
qshell batchdelete --force laijw-book -i laijw-book.list.txt

配置 linux 下载代理 tsocks

下载安装包 wget https://li.nux.ro/download/nux/misc/el7/x86_64/tsocks-1.8-0.14.beta5.el7.nux.x86_64.rpm

安装 rpm -ivh tsocks-1.8-0.14.beta5.el7.nux.x86_64.rpm

修改配置文件 vi /etc/tsocks.conf

填入配置文件内容, 这里192.168.0.41和1088端口 是配置好的socks 5代理服务器,可以使用shadowsocks客户端

local表示本地的网络,也就是不使用socks代理的网络

1
2
3
4
5
local = 192.168.0.0/255.255.255.0
local = 127.0.0.0/255.0.0.0
server = 192.168.0.41
server_type = 5
server_port = 1088