Go中seelog日志包

Go 

1. 介绍 在Go中,seelog是比较有名的日志处理包,功能也比较强大。 2. seelog包的引用 import "github.com/cihub/seelog" 3. 使用 package main import ( log "github.com/cihub/seelog" )

Go计算两个日期之间相差几日、几月

Go 

1. 两个日期相差多少天 time包有个函数Parse可以将时间字符串解析成Time对象,而Time对象有个Sub方法可以计算与某个时间的差,返回值是Duration对象,而Duration有一个Hours方法,除以24就是天数了 // 计算日期相差多少天 // 返回值day>0, t1晚于t2;

Go中文件路径解析

Go 

1. 返回所给路径的绝对路径 // 输出绝对路径 F:\my\bin\log.txt path, _ := filepath.Abs("./log.txt") fmt.Println(path) 2. 返回路径最后一个元素 // 输出 log.txt fmt.Println(filepath.Ba

Go中字符串替换

Go 

在go中,可以用strings包里的Replace方法来做字符串替换 函数申明 package strings // Replace returns a copy of the string s with the first n // non-overlapping instances of ol

Mac中使用密钥连接SSH


1. 打开终端 2. 输入"ls -a" 查看目录,看是否包含 ".ssh"目录,如果没有,创建 root:~ root$ ls -a . .gitignore_global Desktop .. .hgignore_global Documents .CFUserTextEncoding

Goland 保存时自动格式化代码 fmt

Go 

默认情况下,goland idea保存的时候会自动格式化代码的,但是,有时会出现不自动化的情况。下面介绍一下手动配置: 1. File->Settings(Ctrl+Alt+S)打开设置页面 2. 在左侧找到Tools->File Watchers 3. 在左侧添加go fmt 4. 使用默认的配置

Go中使用Google Authenticator

Go 

现在为了安全Google二次验证使用越来越平凡了,所以我们自己做的一些产品中,也会用到Google Authenticator。 介绍 Google Authenticator采用的算法是TOTP(Time-Based One-Time Password基于时间的一次性密码),其核心内容包括以下三点

Go中string和int类型相互转换

Go 

string转成int: int, err := strconv.Atoi(string) string转成int64: int64, err := strconv.ParseInt(string, 10, 64) string转成uint64: uint64, err := strconv.P

Go深度拷贝slice、map

Go 

在Go中没有像Java、C#那种封装好的slice、map深度拷贝函数,下面封装一个 func DeepCopy(value interface{}) interface{} { if valueMap, ok := value.(map[string]interface{}); ok { n

iOS-设置自定义的系统默认字体


1. 先设置自定义的字体 将字体文件拖到工程目录中,并增添加到Bundle中。这里以阿里巴巴普惠体为例。 2. 在info.plist中增加字体 3. 添加字体类 右键创建新文件->选择OC文件 File: 自己定义一个文件名 File Type:Category Class:UIFont 4