1 Star 0 Fork 0

mattu/replication-manager

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
statefile.go 1.48 KB
一键复制 编辑 原始数据 按行查看 历史
Guillaume Lefranc 提交于 2016-08-23 14:49 . Update headers
// replication-manager - Replication Manager Monitoring and CLI for MariaDB
// Authors: Guillaume Lefranc <[email protected]>
// Stephane Varoqui <[email protected]>
// This source code is licensed under the GNU General Public License, version 3.
// Redistribution/Reuse of this code is permitted under the GNU v3 license, as
// an additional term, ALL code must carry the original Author(s) credit in comment form.
// See LICENSE in this directory for the integral text.
package main
import (
"encoding/binary"
"os"
)
type stateFile struct {
Handle *os.File
Name string
Count int32
Timestamp int64
}
func newStateFile(name string) *stateFile {
sf := new(stateFile)
sf.Name = name
return sf
}
func (sf *stateFile) access() error {
var err error
sf.Handle, err = os.OpenFile(sf.Name, os.O_RDWR|os.O_CREATE, 0666)
if err != nil {
return err
}
return nil
}
func (sf *stateFile) write() error {
err := sf.Handle.Truncate(0)
sf.Handle.Seek(0, 0)
if err != nil {
return err
}
err = binary.Write(sf.Handle, binary.LittleEndian, sf.Count)
if err != nil {
return err
}
err = binary.Write(sf.Handle, binary.LittleEndian, sf.Timestamp)
if err != nil {
return err
}
return nil
}
func (sf *stateFile) read() error {
sf.Handle.Seek(0, 0)
err := binary.Read(sf.Handle, binary.LittleEndian, &sf.Count)
if err != nil {
return err
}
err = binary.Read(sf.Handle, binary.LittleEndian, &sf.Timestamp)
if err != nil {
return err
}
return nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mattu/replication-manager.git
[email protected]:mattu/replication-manager.git
mattu
replication-manager
replication-manager
0.7

搜索帮助