package-- time + base64 + log

time包地址:https://pkg.go.dev/time@go1.19.4

time包的作用:Package time provides functionality for measuring and displaying time.
The calendrical calculations always assume a Gregorian calendar, with no leap seconds.

常见的用法:
now = time.Now
now.Format(...)
now.Sub(t)
now.Unix()
now.UnixNano()

const:
time.Second
time.Minute
time.Hour
(应用场景:time.Sleep(time.Second * 5)  -- > 休眠5秒)

func:
d.Hours()
d.Minute()
d.Second()
(将一个time.Duration的d分别转换为小时/分钟/秒)

如何格式化一个时间或日期:
参考文章:
https://yourbasic.org/golang/format-parse-string-time-date-example/

base64包地址:https://pkg.go.dev/encoding/base64@go1.19.4

base64包的作用:Package base64 implements base64 encoding as specified by RFC 4648.

常用func:
1.base64.RawStdEncoding(.EncodeToString/.DecodeString)
2.base64.URLEncoding(.EncodeToString/.DecodeString)
3.base64.RawURLEncoding(.EncodeToString/.DecodeString)
4.base64.StdEncoding.EncodeToString
  函数:func (enc *Encoding) EncodeToString(src  []bytestring
  返回值:EncodeToString returns the base64 encoding of src
5.base64.StdEncoding.DecodeString
  函数:func (enc *Encoding)  DecodeString(s string)  ([]byteerror)
  返回值:DecodeString returns the bytes represented by the base64 string s

log包地址:https://pkg.go.dev/log

log包的作用:Package log implements a simple logging package. It defines a type, Logger, with methods for formatting output. It also has a predefined 'standard' Logger accessible through helper functions Print[f|ln], Fatal[f|ln], and Panic[f|ln], which are easier to use than creating a Logger manually. That logger writes to standard error and prints the date and time of each logged message. Every log message is output on a separate line: if the message being printed does not end in a newline, the logger will add one. The Fatal functions call os.Exit(1) after writing the log message. The Panic functions call panic after writing the log message.

常用:
Fatal:打印日志,并退出程序
Fatalf
Fatalln

Panic:打印日志,并产生panic
Panicf
Panicln

Printf:打印日志(最常用)
Println

SetFlags
Flags

SetOutput:把日志写到文件里

SetPrefix: 在日志前加上前缀,可用于对日志进行分类

Flag
SetFlags

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容