主页

MongoDB 运行 js 脚本

我们通常通过 Mongo Shell 访问 MongoDB Server,在 shell 中执行指令以完成各种操作,比如说复制集初始化、用户添加等等。但是,在实际过程中运维过程中有些操作是固定常用的,类似这些操作我们可以将其写入 js 文件,在Linux的 shell 中执行 mongo xxx.js 这样指令完成我们的操作。

阅读更多

iPhone 使用 MAC 上的 Socks 代理

Step 1. Make sure the SOCKS tunnel on your work computer allows LAN connections so your iPhone/iPod Touch can connect to it. $ ssh -N -g -D 1080 user@domain.com Step 2. Create a text file and insert the following code: function FindProxyForURL(url, host) { return "SOCKS 192.168.xx.xx:yyyy"; } Replace the x’s with your IP and the y’s ...

阅读更多

Golang 的文件和目录

获取目录中的所有文件 io/ioutil ioutil.ReadDir // ReadDir reads the directory named by dirname and returns // a list of directory entries sorted by filename. func ReadDir(dirname string) ([]os.FileInfo, error) { f, err := os.Open(dirname) if err != nil { return nil, err } list, err := f.Readdir(-1) f.Close() if err != nil { return nil, err } ...

阅读更多

Golang context 包

在 Go http 包的 Server 中,每一个请求在都有一个对应的goroutine去处理。请求处理函数通常会启动额外的goroutine用来访问后端服务,比如数据库和 RPC 服务。用来处理一个请求的goroutine通常需要访问一些与请求特定的数据,比如终端用户的身份认证信息、验证相关的 token、请求的截止时间。当一个请求被取消或超时时,所有用来处理该请求的goroutine都应该迅速退出,然后系统才能释放这些goroutine占用的资源,官方博客。 注意:go1.6及之前版本请使用golang.org/x/net/context。go1.7及之后已移到标准库context。

阅读更多