// updateXChecksum 更新XChecksum, 在之前该方法前, 需要上锁. func (lg *logger) updateXChecksum(log []byte) { lg.xChecksum = calChecksum(lg.xChecksum, log) _, err := lg.file.WriteAt(utils.Uint32ToRaw(lg.xChecksum), 0) if err != nil { panic(err) } err = lg.file.Sync() if err != nil { panic(err) } }
func Create(path string) *logger { file, err := os.OpenFile(path+SUFFIX_LOG, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { panic(err) } xChecksum := utils.Uint32ToRaw(0) _, err = file.Write(xChecksum) if err != nil { panic(err) } err = file.Sync() if err != nil { panic(err) } lg := new(logger) lg.file = file lg.xChecksum = 0 return lg }