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 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 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 WriteFile(target string, flag int, mode os.FileMode, data ...string) error
- type Gossip
- 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 ( 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 ListContains ¶
func ListDelete ¶
func MergeFiles ¶
func MkdirIfNotExist ¶
func RandomString ¶
Types ¶
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 { Id uuid.UUID Spec *ScriptSpec Cmd *exec.Cmd Runnable // contains filtered or unexported fields }
func NewScript ¶
func NewScript(s *ScriptSpec) (*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()