1 Star 1 Fork 0

李爽 / go-utils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
base.go 612 Bytes
一键复制 编辑 原始数据 按行查看 历史
package obj
import (
"fmt"
"sync"
)
type Base[T comparable] struct {
Value T
mux sync.RWMutex
}
// Get 返回基对象的值。
func (c *Base[T]) Get() T {
c.mux.RLock()
defer c.mux.RUnlock()
return c.Value
}
// Set 设置基对象的值。
func (c *Base[T]) Set(value T) {
c.mux.Lock()
c.Value = value
c.mux.Unlock()
}
// Display 打印基对象的值。
func (c *Base[T]) Display() {
c.mux.RLock()
defer c.mux.RUnlock()
fmt.Println(c.Value)
}
// DisplayType 打印基对象的类型。
func (c *Base[T]) DisplayType() {
c.mux.RLock()
defer c.mux.RUnlock()
fmt.Printf("%T\n", c.Value)
}
Go
1
https://gitee.com/love_bass/go-utils.git
git@gitee.com:love_bass/go-utils.git
love_bass
go-utils
go-utils
v0.6.6

搜索帮助