blog
blog copied to clipboard
Timer 的使用一般来说有如下几点: - 对操作做超时处理 - 定时多久后执行某个方法 > 注意 Timer 只执行一次,Ticker 可以循环执行。类似于 js 中的 setTimeout 与 setInterval 的区别。 ## Timer 例子 ### 定时多久后执行某个方法 ```go func main() { _ = time.AfterFunc(2 *...
**参考文档:** - https://wiki.ubuntu.com/UpdateMotd#Design Linux 公告板是个很有意思的东西。 在你通过 SSH 链接上主机后,在界面上能够打印出来上次登录时间、CPU、提示等等自定义的东西。 首先,cd /etc/update-motd.d 文件夹: ```shell root@core-1:/etc/update-motd.d# cd /etc/update-motd.d/ root@core-1:/etc/update-motd.d# ls -l total 24 -rwxr-xr-x 1 root root 1220 Oct 23 2015 00-header -rwxr-xr-x...
参考: - https://gocn.io/question/265 - https://stackoverflow.com/questions/1760757/how-to-efficiently-concatenate-strings-in-go/23857998#23857998 ## 字符串操作 go 的字符串操作有如下的方式,我们用累加 `ABCD ` 1000 次举例 - `+` 操作符 ```go var result string str := "ABCD " for i := 0; i <...
Bash 的别名和函数能够节约用户时间。 **别名的作用?** 用户可以自定义一个短命令来代替一个长命令 **函数的作用?** 别名已经很有用了,函数能做什么?函数能够让用户自定义一个短命令,来代替多个命令。并且能够接受参数 ## 别名 我们可以在 `~/.bashrc` 文件中定义,也可以在 `~/.bash_aliases` 文件中定义 按照如下方法,我们可以简单定义一个短命令 ```shell root@pelin:~# cd ~ # 进入用户主目录 root@pelin:~# vim .bash_aliases # 编辑 aliases 文件,没有则新建 alias llss='ls -alF'...