comment update for package gconv/gproc

This commit is contained in:
John Guo
2021-05-17 21:26:39 +08:00
parent b84ca9cc13
commit 0dfd968824
11 changed files with 61 additions and 60 deletions

View File

@ -7,7 +7,6 @@
package gfsnotify_test
import (
"fmt"
"github.com/gogf/gf/container/garray"
"testing"
"time"
@ -205,7 +204,7 @@ func TestWatcher_WatchFolderWithoutRecursively(t *testing.T) {
t.AssertNil(err)
_, err = gfsnotify.Add(dirPath, func(event *gfsnotify.Event) {
fmt.Println(event.String())
//fmt.Println(event.String())
array.Append(1)
}, false)
t.AssertNil(err)

View File

@ -12,26 +12,27 @@ import (
"github.com/gogf/gf/container/gmap"
)
// 进程管理器
// Manager is a process manager maintaining multiple processes.
type Manager struct {
processes *gmap.IntAnyMap // 所管理的子进程map
processes *gmap.IntAnyMap // Process id to Process object mapping.
}
// 创建一个进程管理器
// NewManager creates and returns a new process manager.
func NewManager() *Manager {
return &Manager{
processes: gmap.NewIntAnyMap(true),
}
}
// 创建一个进程(不执行)
// NewProcess creates and returns a Process object.
func (m *Manager) NewProcess(path string, args []string, environment []string) *Process {
p := NewProcess(path, args, environment)
p.Manager = m
return p
}
// 获取当前进程管理器中的一个进程
// GetProcess retrieves and returns a Process object.
// It returns nil if it does not find the process with given `pid`.
func (m *Manager) GetProcess(pid int) *Process {
if v := m.processes.Get(pid); v != nil {
return v.(*Process)
@ -39,7 +40,8 @@ func (m *Manager) GetProcess(pid int) *Process {
return nil
}
// 添加一个已存在进程到进程管理器中
// AddProcess adds a process to current manager.
// It does nothing if the process with given `pid` does not exist.
func (m *Manager) AddProcess(pid int) {
if m.processes.Get(pid) == nil {
if process, err := os.FindProcess(pid); err == nil {
@ -50,12 +52,12 @@ func (m *Manager) AddProcess(pid int) {
}
}
// 移除进程管理器中的指定进程
// RemoveProcess removes a process from current manager.
func (m *Manager) RemoveProcess(pid int) {
m.processes.Remove(pid)
}
// 获取所有的进程对象,构成列表返回
// Processes retrieves and returns all processes in current manager.
func (m *Manager) Processes() []*Process {
processes := make([]*Process, 0)
m.processes.RLockFunc(func(m map[int]interface{}) {
@ -66,12 +68,12 @@ func (m *Manager) Processes() []*Process {
return processes
}
// 获取所有的进程pid构成列表返回
// Pids retrieves and returns all process id array in current manager.
func (m *Manager) Pids() []int {
return m.processes.Keys()
}
// 等待所有子进程结束
// WaitAll waits until all process exit.
func (m *Manager) WaitAll() {
processes := m.Processes()
if len(processes) > 0 {
@ -81,7 +83,7 @@ func (m *Manager) WaitAll() {
}
}
// 关闭所有的进程
// KillAll kills all processes in current manager.
func (m *Manager) KillAll() error {
for _, p := range m.Processes() {
if err := p.Kill(); err != nil {
@ -91,7 +93,7 @@ func (m *Manager) KillAll() error {
return nil
}
// 向所有进程发送信号量
// SignalAll sends a signal `sig` to all processes in current manager.
func (m *Manager) SignalAll(sig os.Signal) error {
for _, p := range m.Processes() {
if err := p.Signal(sig); err != nil {
@ -101,24 +103,24 @@ func (m *Manager) SignalAll(sig os.Signal) error {
return nil
}
// 向所有进程发送消息
// Send sends data bytes to all processes in current manager.
func (m *Manager) Send(data []byte) {
for _, p := range m.Processes() {
p.Send(data)
}
}
// 向指定进程发送消息
// SendTo sneds data bytes to specified processe in current manager.
func (m *Manager) SendTo(pid int, data []byte) error {
return Send(pid, data)
}
// 清空管理器
// Clear removes all processes in current manager.
func (m *Manager) Clear() {
m.processes.Clear()
}
// 当前进程总数
// Size returns the size of processes in current manager.
func (m *Manager) Size() int {
return m.processes.Size()
}

View File

@ -53,7 +53,7 @@ func AddSigHandlerShutdown(handler SigHandler) {
}
}
// ListenSignal blocks and does signal listening and handling.
// Listen blocks and does signal listening and handling.
func Listen() {
signals := make([]os.Signal, 0)
for sig, _ := range signalHandlerMap {

View File

@ -45,7 +45,7 @@ var (
StructTagPriority = []string{"gconv", "param", "params", "c", "p", "json"}
)
// Convert converts the variable `i` to the type `t`, the type `t` is specified by string.
// Convert converts the variable `any` to the type `t`, the type `t` is specified by string.
// The optional parameter `params` is used for additional necessary parameter for this conversion.
// It supports common types conversion as its conversion based on type name string.
func Convert(any interface{}, t string, params ...interface{}) interface{} {
@ -277,7 +277,7 @@ func Convert(any interface{}, t string, params ...interface{}) interface{} {
}
}
// Byte converts `i` to byte.
// Byte converts `any` to byte.
func Byte(any interface{}) byte {
if v, ok := any.(byte); ok {
return v
@ -285,7 +285,7 @@ func Byte(any interface{}) byte {
return Uint8(any)
}
// Bytes converts `i` to []byte.
// Bytes converts `any` to []byte.
func Bytes(any interface{}) []byte {
if any == nil {
return nil
@ -303,7 +303,7 @@ func Bytes(any interface{}) []byte {
}
}
// Rune converts `i` to rune.
// Rune converts `any` to rune.
func Rune(any interface{}) rune {
if v, ok := any.(rune); ok {
return v
@ -311,7 +311,7 @@ func Rune(any interface{}) rune {
return rune(Int32(any))
}
// Runes converts `i` to []rune.
// Runes converts `any` to []rune.
func Runes(any interface{}) []rune {
if v, ok := any.([]rune); ok {
return v
@ -319,7 +319,7 @@ func Runes(any interface{}) []rune {
return []rune(String(any))
}
// String converts `i` to string.
// String converts `any` to string.
// It's most common used converting function.
func String(any interface{}) string {
if any == nil {
@ -422,8 +422,8 @@ func String(any interface{}) string {
}
}
// Bool converts `i` to bool.
// It returns false if `i` is: false, "", 0, "false", "off", "no", empty slice/map.
// Bool converts `any` to bool.
// It returns false if `any` is: false, "", 0, "false", "off", "no", empty slice/map.
func Bool(any interface{}) bool {
if any == nil {
return false
@ -467,7 +467,7 @@ func Bool(any interface{}) bool {
}
}
// Int converts `i` to int.
// Int converts `any` to int.
func Int(any interface{}) int {
if any == nil {
return 0
@ -478,7 +478,7 @@ func Int(any interface{}) int {
return int(Int64(any))
}
// Int8 converts `i` to int8.
// Int8 converts `any` to int8.
func Int8(any interface{}) int8 {
if any == nil {
return 0
@ -489,7 +489,7 @@ func Int8(any interface{}) int8 {
return int8(Int64(any))
}
// Int16 converts `i` to int16.
// Int16 converts `any` to int16.
func Int16(any interface{}) int16 {
if any == nil {
return 0
@ -500,7 +500,7 @@ func Int16(any interface{}) int16 {
return int16(Int64(any))
}
// Int32 converts `i` to int32.
// Int32 converts `any` to int32.
func Int32(any interface{}) int32 {
if any == nil {
return 0
@ -511,7 +511,7 @@ func Int32(any interface{}) int32 {
return int32(Int64(any))
}
// Int64 converts `i` to int64.
// Int64 converts `any` to int64.
func Int64(any interface{}) int64 {
if any == nil {
return 0
@ -592,7 +592,7 @@ func Int64(any interface{}) int64 {
}
}
// Uint converts `i` to uint.
// Uint converts `any` to uint.
func Uint(any interface{}) uint {
if any == nil {
return 0
@ -603,7 +603,7 @@ func Uint(any interface{}) uint {
return uint(Uint64(any))
}
// Uint8 converts `i` to uint8.
// Uint8 converts `any` to uint8.
func Uint8(any interface{}) uint8 {
if any == nil {
return 0
@ -614,7 +614,7 @@ func Uint8(any interface{}) uint8 {
return uint8(Uint64(any))
}
// Uint16 converts `i` to uint16.
// Uint16 converts `any` to uint16.
func Uint16(any interface{}) uint16 {
if any == nil {
return 0
@ -625,7 +625,7 @@ func Uint16(any interface{}) uint16 {
return uint16(Uint64(any))
}
// Uint32 converts `i` to uint32.
// Uint32 converts `any` to uint32.
func Uint32(any interface{}) uint32 {
if any == nil {
return 0
@ -636,7 +636,7 @@ func Uint32(any interface{}) uint32 {
return uint32(Uint64(any))
}
// Uint64 converts `i` to uint64.
// Uint64 converts `any` to uint64.
func Uint64(any interface{}) uint64 {
if any == nil {
return 0
@ -699,7 +699,7 @@ func Uint64(any interface{}) uint64 {
}
}
// Float32 converts `i` to float32.
// Float32 converts `any` to float32.
func Float32(any interface{}) float32 {
if any == nil {
return 0
@ -720,7 +720,7 @@ func Float32(any interface{}) float32 {
}
}
// Float64 converts `i` to float64.
// Float64 converts `any` to float64.
func Float64(any interface{}) float64 {
if any == nil {
return 0

View File

@ -23,7 +23,7 @@ func SliceStruct(params interface{}, pointer interface{}, mapping ...map[string]
return Structs(params, pointer, mapping...)
}
// Maps converts `i` to []map[string]interface{}.
// Maps converts `value` to []map[string]interface{}.
// Note that it automatically checks and converts json string to []map if `value` is string/[]byte.
func Maps(value interface{}, tags ...string) []map[string]interface{} {
if value == nil {
@ -68,7 +68,7 @@ func Maps(value interface{}, tags ...string) []map[string]interface{} {
}
}
// MapsDeep converts `i` to []map[string]interface{} recursively.
// MapsDeep converts `value` to []map[string]interface{} recursively.
//
// TODO completely implement the recursive converting for all types.
func MapsDeep(value interface{}, tags ...string) []map[string]interface{} {

View File

@ -15,7 +15,7 @@ func SliceAny(any interface{}) []interface{} {
return Interfaces(any)
}
// Interfaces converts `i` to []interface{}.
// Interfaces converts `any` to []interface{}.
func Interfaces(any interface{}) []interface{} {
if any == nil {
return nil

View File

@ -23,12 +23,12 @@ func SliceFloat64(any interface{}) []float64 {
return Floats(any)
}
// Floats converts `i` to []float64.
// Floats converts `any` to []float64.
func Floats(any interface{}) []float64 {
return Float64s(any)
}
// Float32s converts `i` to []float32.
// Float32s converts `any` to []float32.
func Float32s(any interface{}) []float32 {
if any == nil {
return nil
@ -148,7 +148,7 @@ func Float32s(any interface{}) []float32 {
return array
}
// Float64s converts `i` to []float64.
// Float64s converts `any` to []float64.
func Float64s(any interface{}) []float64 {
if any == nil {
return nil

View File

@ -23,7 +23,7 @@ func SliceInt64(any interface{}) []int64 {
return Int64s(any)
}
// Ints converts `i` to []int.
// Ints converts `any` to []int.
func Ints(any interface{}) []int {
if any == nil {
return nil
@ -153,7 +153,7 @@ func Ints(any interface{}) []int {
return array
}
// Int32s converts `i` to []int32.
// Int32s converts `any` to []int32.
func Int32s(any interface{}) []int32 {
if any == nil {
return nil
@ -283,7 +283,7 @@ func Int32s(any interface{}) []int32 {
return array
}
// Int64s converts `i` to []int64.
// Int64s converts `any` to []int64.
func Int64s(any interface{}) []int64 {
if any == nil {
return nil

View File

@ -13,7 +13,7 @@ func SliceStr(any interface{}) []string {
return Strings(any)
}
// Strings converts `i` to []string.
// Strings converts `any` to []string.
func Strings(any interface{}) []string {
if any == nil {
return nil

View File

@ -23,7 +23,7 @@ func SliceUint64(any interface{}) []uint64 {
return Uint64s(any)
}
// Uints converts `i` to []uint.
// Uints converts `any` to []uint.
func Uints(any interface{}) []uint {
if any == nil {
return nil
@ -149,7 +149,7 @@ func Uints(any interface{}) []uint {
return array
}
// Uint32s converts `i` to []uint32.
// Uint32s converts `any` to []uint32.
func Uint32s(any interface{}) []uint32 {
if any == nil {
return nil
@ -274,7 +274,7 @@ func Uint32s(any interface{}) []uint32 {
return array
}
// Uint64s converts `i` to []uint64.
// Uint64s converts `any` to []uint64.
func Uint64s(any interface{}) []uint64 {
if any == nil {
return nil

View File

@ -13,7 +13,7 @@ import (
"github.com/gogf/gf/os/gtime"
)
// Time converts `i` to time.Time.
// Time converts `any` to time.Time.
func Time(any interface{}, format ...string) time.Time {
// It's already this type.
if len(format) == 0 {
@ -27,9 +27,9 @@ func Time(any interface{}, format ...string) time.Time {
return time.Time{}
}
// Duration converts `i` to time.Duration.
// If `i` is string, then it uses time.ParseDuration to convert it.
// If `i` is numeric, then it converts `i` as nanoseconds.
// Duration converts `any` to time.Duration.
// If `any` is string, then it uses time.ParseDuration to convert it.
// If `any` is numeric, then it converts `any` as nanoseconds.
func Duration(any interface{}) time.Duration {
// It's already this type.
if v, ok := any.(time.Duration); ok {
@ -43,10 +43,10 @@ func Duration(any interface{}) time.Duration {
return time.Duration(Int64(any))
}
// GTime converts `i` to *gtime.Time.
// The parameter `format` can be used to specify the format of `i`.
// If no `format` given, it converts `i` using gtime.NewFromTimeStamp if `i` is numeric,
// or using gtime.StrToTime if `i` is string.
// GTime converts `any` to *gtime.Time.
// The parameter `format` can be used to specify the format of `any`.
// If no `format` given, it converts `any` using gtime.NewFromTimeStamp if `any` is numeric,
// or using gtime.StrToTime if `any` is string.
func GTime(any interface{}, format ...string) *gtime.Time {
if any == nil {
return nil