0 Star 0 Fork 650

李明/gf

forked from John/gf 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
bytes.go 988 Bytes
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2018 gf Author(https://gitee.com/johng/gf). All Rights Reserved.
//
// This Source Code Form is subject to the terms of the MIT License.
// If a copy of the MIT was not distributed with this file,
// You can obtain one at https://gitee.com/johng/gf.
package gtype
import (
"sync"
)
type Bytes struct {
mu sync.RWMutex
val []byte
}
func NewBytes(value...[]byte) *Bytes {
if len(value) > 0 {
return &Bytes{val:value[0]}
}
return &Bytes{}
}
func (t *Bytes)Set(value []byte) {
t.mu.Lock()
t.val = value
t.mu.Unlock()
}
func (t *Bytes)Val() []byte {
t.mu.RLock()
b := t.val
t.mu.RUnlock()
return b
}
// 使用自定义方法执行加锁修改操作
func (t *Bytes) LockFunc(f func(value []byte) []byte) {
t.mu.Lock()
t.val = f(t.val)
t.mu.Unlock()
}
// 使用自定义方法执行加锁读取操作
func (t *Bytes) RLockFunc(f func(value []byte)) {
t.mu.RLock()
f(t.val)
t.mu.RUnlock()
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/limingsky/gf.git
git@gitee.com:limingsky/gf.git
limingsky
gf
gf
c9a36a8224f1

搜索帮助