西维蜀黍

【Golang】Golang 版本管理

Installing multiple Go versions

You can install multiple Go versions on the same machine. For example, you might want to test your code on multiple Go versions. For a list of versions you can install this way, see the download page.

Note: To install using the method described here, you’ll need to have git installed.

To install additional Go versions, run the go install command, specifying the download location of the version you want to install. The following example illustrates with version 1.10.7:

$ go install golang.org/dl/go1.10.7@latest
$ go1.10.7 download

To run go commands with the newly-downloaded version, append the version number to the go command, as follows:

$ go1.10.7 version
go version go1.10.7 linux/amd64

When you have multiple versions installed, you can discover where each is installed, look at the version’s GOROOT value. For example, run a command such as the following:

$ go1.10.7 env GOROOT
  ...


【Golang】代码检查

易犯错误

幽灵变量(shadowed variables)

如果你在新的代码块中像下边这样误用了 :=,编译不会报错,但是变量不会按你的预期工作:

func main() {
	x := 1
	println(x)		// 1
	{
		println(x)	// 1
		x := 2
		println(x)	// 2	// 新的 x 变量的作用域只在代码块内部
	}
	println(x)		// 1
}

Solution: go-nyet

  ...


【Golang】幽灵变量(Shadowed Variables)

幽灵变量(Shadowed Variables)

Example 1

如果你在新的代码块中像下边这样误用了 :=,编译不会报错,但是变量不会按你的预期工作:

func main() {
	x := 1
	println(x)		// 1
	{
		println(x)	// 1
		x := 2
		println(x)	// 2	// 新的 x 变量的作用域只在代码块内部
	}
	println(x)		// 1
}

这是 Go 开发者常犯的错,而且不易被发现。

  ...


【OpenWrt】OpenWrt 学习

OpenWrt 网络接口(Network Interfaces)

物理网络接口(Physical Network Interfaces)

eth0, eth8, radio0, wlan19, .. 这些符号总是代表着真实存在的网络设备。 例如: [NIC](https://en.wikipedia.org/wiki/Network interface controller), [WNIC](https://en.wikipedia.org/wiki/Wireless network interface controller) 或其他一些 Modem。当[device driver](https://en.wikipedia.org/wiki/device driver)被作为物理网络接口的驱动加载进内核,这些网络接口就可用了。

任何物理网络接口是由操作系统为用户命名的软件的网络接口,以使得操作系统配置物理网络设备并且将其集成到程序和脚本中。

  ...


【macOS】移除默认输入法

  • 关闭 macOS 的 SIP

  • 将输入法切换为系统自带的 ABC 输入法,然后打开终端输入以下命令:

    $ sudo open ~/Library/Preferences/com.apple.HIToolbox.plist
    
  • 以打开 com.apple.HIToolbox.plist 文件(打开 .plist 文件需要安装有如 Xcode)

  • 依次点开 Root - AppleEnabledInputSources ,会看到一列 item ,找到其中 KeyboardLayout Name 为 ABC 的那一列,将整列 item 删掉,然后 command + S 保存。

  • 接着重启电脑,打开键盘设置,就可以看到系统自带的 ABC 输入法已经被删掉了。

  ...


【Network】NAT

  ...


【VMware】安装 VMware ESXi 7.0.3

Download

ISO

https://customerconnect.vmware.com/en/downloads/details?downloadGroup=ESXI70U3C&productId=974&rPId=84824 下载 VMware ESXi

  ...


【OpenWrt】查看 CPU 温度

$ cut -c1-2 /sys/class/thermal/thermal_zone0/temp
  ...


【Network】tcpdump 抓包

OpenWrt安装

$ opkg update && opkg install tcpdump

Usage

默认启动

$ tcpdump

普通情况下,直接启动tcpdump将监视第一个网络接口上所有流过的数据包。

# get list of interfaces
$ ifconfig

# do tcpdump on lan interface 'br-lan'
$ tcpdump -i br-lan -n

# dump for http traffic
$ tcpdump -i br-lan port 80

# dump for ssh traffic on wan, but do not show self
$ tcpdump -i eth0 port 22 and not host 192.168.1.7
  ...


【Linux】修改 MAC 地址

Linux

获取mac地址

$ ip link show
enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
 link/ether 08:xx:xx:xx:xx:x1 brd ff:ff:ff:ff:ff:ff

或者:

$ ifconfig | grep HWaddr
enp0s3    Link encap:Ethernet  HWaddr 08:xx:xx:xx:xx:x1
  ...