Documentation ¶
Overview ¶
Copyright (c) 2022 Yaohui Wang (yaohuiwang@outlook.com) utils is licensed under Mulan PubL v2. You can use this software according to the terms and conditions of the Mulan PubL v2. You may obtain a copy of Mulan PubL v2 at:
http://license.coscl.org.cn/MulanPubL-2.0
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PubL v2 for more details.
Copyright (c) 2022 Yaohui Wang (yaohuiwang@outlook.com) utils is licensed under Mulan PubL v2. You can use this software according to the terms and conditions of the Mulan PubL v2. You may obtain a copy of Mulan PubL v2 at:
http://license.coscl.org.cn/MulanPubL-2.0
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. See the Mulan PubL v2 for more details.
Index ¶
- Constants
- Variables
- func AllocIPFromCidr(cidr string, exist []string) (*string, error)
- func AllocIPFromRange(start string, end string, exist []string) (*string, error)
- func CreateFile(target string, data ...string) error
- func DelFileIfExist(f string) error
- func Equal(a interface{}, b interface{}) bool
- func ExecCommand(cmd string) (int, error)
- func FileExist(f string) bool
- func GetIPStatus(ipaddress string, prefix *uint8, dev *string) string
- func GetInterfaceOfIP(ipaddress string) (*string, *int, error)
- func GetInterfaceStatus(dev *string) string
- func GetProcStatus(pidFile string) string
- func IpInNetwork(ipstr string, cidr string) bool
- func Ipv4ToUint32(ipv4 string) (uint32, error)
- func ListContains(slice []string, obj string) bool
- func ListDelete(slice []string, obj string) (result []string)
- func LogPrintf(level int, module string, format string, v ...interface{})
- func MergeFiles(target string, files ...string) error
- func MkdirIfNotExist(path string) error
- func RandNum(max int) int
- func RandomString(len int) string
- func Uint32ToIpv4(ipv4Uint32 uint32) string
- func WriteFile(target string, flag int, mode os.FileMode, data ...string) error
- type Bitmap
- func (a *Bitmap) And(other Bitmap, extra ...Bitmap)
- func (a *Bitmap) AndNot(other Bitmap, extra ...Bitmap)
- func (b *Bitmap) Clear()
- func (b *Bitmap) Contains(x uint32) bool
- func (b *Bitmap) Count() int
- func (b *Bitmap) CountTo(until uint32) int
- func (b *Bitmap) Grow(desiredBit uint32)
- func (b *Bitmap) MarshalJSON() ([]byte, error)
- func (b *Bitmap) Max() (uint32, bool)
- func (b *Bitmap) MaxZero() (uint32, bool)
- func (b *Bitmap) Min() (uint32, bool)
- func (b *Bitmap) MinZero() (uint32, bool)
- func (b *Bitmap) Ones()
- func (a *Bitmap) Or(other Bitmap, extra ...Bitmap)
- func (b *Bitmap) Remove(x uint32)
- func (b *Bitmap) Set(x uint32)
- func (b *Bitmap) ToBytes() (out []byte)
- func (b *Bitmap) ToHexBitmap() *HexBitmap
- func (b *Bitmap) ToString() string
- func (b *Bitmap) UnmarshalJSON(data []byte) (err error)
- func (a *Bitmap) Xor(other Bitmap, extra ...Bitmap)
- type Gossip
- type HexBitmap
- type Runnable
- type Script
- type ScriptSpec
- type ThreadPool
Constants ¶
const ( LOG_DEBUG int = iota LOG_INFO LOG_WARN LOG_ERROR )
const ( MODE_PERM_RW fs.FileMode = 0600 MODE_PERM_RO fs.FileMode = 0400 )
const ( STATUS_UP string = "up" STATUS_DOWN string = "down" STATUS_PENDING string = "pending" )
const ( ScriptStatusWaiting = "waiting" ScriptStatusRunning = "running" ScriptStatusExited = "exited" ScriptStatusKilled = "killed" ScriptStatusFailed = "failed_start" )
const ( DefaultThreadQueueSize int = 64 DefaultThreadPoolSize int = 8 )
Variables ¶
Functions ¶
func AllocIPFromCidr ¶
allocate ip from cidr
func AllocIPFromRange ¶
allocate ip from range
func CreateFile ¶
func DelFileIfExist ¶
func ExecCommand ¶
func GetInterfaceStatus ¶
func GetProcStatus ¶
func Ipv4ToUint32 ¶ added in v0.1.9
convert ipv4 to unit32
func ListContains ¶
func ListDelete ¶
func MergeFiles ¶
func MkdirIfNotExist ¶
func RandomString ¶
func Uint32ToIpv4 ¶ added in v0.1.10
convert unit32 to ipv4
Types ¶
type Bitmap ¶ added in v0.2.6
type Bitmap struct {
// contains filtered or unexported fields
}
func FromBytes ¶ added in v0.2.6
FromBytes reads a bitmap from a byte buffer without copying the buffer.
func FromString ¶ added in v0.2.6
FromString decodes the received string and loads it to bitmap object
func (*Bitmap) And ¶ added in v0.2.6
And computes the intersection between two bitmaps and stores the result in the current bitmap
func (*Bitmap) AndNot ¶ added in v0.2.6
AndNot computes the difference between two bitmaps and stores the result in the current bitmap. Operation works as set subtract: a - b
func (*Bitmap) Clear ¶ added in v0.2.6
func (b *Bitmap) Clear()
Clear clears the bitmap and resizes it to zero.
func (*Bitmap) Contains ¶ added in v0.2.6
Contains checks whether a value is contained in the bitmap or not.
func (*Bitmap) CountTo ¶ added in v0.2.6
CountTo counts the number of elements in the bitmap up until the specified index. If until is math.MaxUint32, it will return the count. The count is non-inclusive of the index.
func (*Bitmap) MarshalJSON ¶ added in v0.2.6
func (*Bitmap) Max ¶ added in v0.2.6
Max get the largest value stored in this bitmap, assuming the bitmap is not empty.
func (*Bitmap) MaxZero ¶ added in v0.2.6
MaxZero get the last zero bit and return its index, assuming bitmap is not empty
func (*Bitmap) Min ¶ added in v0.2.6
Min get the smallest value stored in this bitmap, assuming the bitmap is not empty.
func (*Bitmap) MinZero ¶ added in v0.2.6
MinZero finds the first zero bit and returns its index, assuming the bitmap is not empty.
func (*Bitmap) Or ¶ added in v0.2.6
Or computes the union between two bitmaps and stores the result in the current bitmap
func (*Bitmap) Remove ¶ added in v0.2.6
Remove removes the bit x from the bitmap, but does not shrink it.
func (*Bitmap) ToBytes ¶ added in v0.2.6
ToBytes converts the bitmap to binary representation without copying the underlying data. The output buffer should not be modified, since it would also change the bitmap.
func (*Bitmap) ToHexBitmap ¶ added in v0.2.6
func (*Bitmap) ToString ¶ added in v0.2.6
ToString returns encoded string representation for the bitmap
func (*Bitmap) UnmarshalJSON ¶ added in v0.2.6
type Gossip ¶
type Gossip struct { Name string BindAddr string BindPort int SecretKey []byte ProbeInterval int SyncInterval int RetransmitMult int Ready bool NotifyJoinHandler func(*memberlist.Node) NotifyLeaveHandler func(*memberlist.Node) NotifyUpdateHandler func(*memberlist.Node) InvalidatesHandler func(memberlist.Broadcast) bool NodeMetaHandler func() []byte NotifyMsgHandler func([]byte) LocalStateHandler func() []byte MergeRemoteStateHandler func([]byte) // contains filtered or unexported fields }
func DefaultGossip ¶
func DefaultGossip() *Gossip
Generage a default broadcast, need to set handlers:
- NotifyMsgHandler
- LocalStateHandler
- MergeRemoteStateHandler
type Script ¶
type Script struct { Spec *ScriptSpec Cmd *exec.Cmd Status string Runnable // contains filtered or unexported fields }
func NewScript ¶
func NewScript(s *ScriptSpec, callback func()) (*Script, error)
type ScriptSpec ¶
type ThreadPool ¶
type ThreadPool struct { QueueSize int PoolSize int Queue chan Runnable // contains filtered or unexported fields }
func DefaultThreadPool ¶
func DefaultThreadPool() *ThreadPool
func NewThreadPool ¶
func NewThreadPool(QueueSize int, PoolSize int) *ThreadPool
func (*ThreadPool) Destroy ¶
func (p *ThreadPool) Destroy()
func (*ThreadPool) Init ¶
func (p *ThreadPool) Init()
func (*ThreadPool) Put ¶
func (p *ThreadPool) Put(r Runnable) error
func (*ThreadPool) Wait ¶
func (p *ThreadPool) Wait()