Golang开发中常用的代码片段汇总

2020-01-28 12:23:26王旭

重点:

      1.使用bson修饰符 

      2.各个flag直接使用空格分割 

      3._id和omitempty使用,分割。同时不能存在空格 

七、定时器


 for {
  now := time.Now()
  next := now.Add(time.Minute * 10)
  next = time.Date(next.Year(), next.Month(), next.Day(), next.Hour(), next.Minute(), 0, 0, next.Location())
  t := time.NewTimer(next.Sub(now))
  log.Printf("下次采集时间为[%s]n", next.Format("200601021504"))

  select {
  case <-t.C:
   err := sync.Gather()
   if err != nil {
    log.Println(err)
   }
  }
 }

总结

以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对易采站长站的支持。