mirror of
https://github.com/nabbar/golib.git
synced 2025-10-05 15:56:50 +08:00

Add feature to change http timeout directly in httpcli store in aws client Add copy/MPUCopy function Update mpu to allow copy with MPU Package Cobra Fix println by fmt.Fprint to os.stdout Package Crypt Refactor package to use instance of crypt instead of a global crypt unique instance Allow to gen key/nonce Add io stream reader/writer instead of only buffer slice encoder decoder Package file/bandwidth Add new subpackage bandwith to limit a amount of byte read/write for a duraction Use file/progress function increment/reset Allow to add custom function increment / reset Package IOUtils Remove useless file error.go, tempFile.go (replaced by package file) Move fileDescriptor to a subpackage fileDescriptor: allow to change nb of FD for linux/windows os Move Buffer ReadCloser to a new subpackage: allow to add close function to buffer, and expose read / write io interface Add sub package multiplexer to allow send/receive multiple io stream into on io stream Package Socket Rework to expose io stream instead of buffer Fix minor bugs Other: Bump dependencies Update code following bump dependencies
105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
//go:build examples
|
|
// +build examples
|
|
|
|
/*
|
|
* MIT License
|
|
*
|
|
* Copyright (c) 2020 Nicolas JUHEL
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
* in the Software without restriction, including without limitation the rights
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
* furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"math/rand"
|
|
"time"
|
|
|
|
"github.com/nabbar/golib/progress"
|
|
libsem "github.com/nabbar/golib/semaphore"
|
|
"github.com/vbauerster/mpb/v5"
|
|
)
|
|
|
|
func main() {
|
|
tot := int64(1000)
|
|
inc := int64(1)
|
|
nbb := 5
|
|
bar := make([]progress.Bar, 0)
|
|
|
|
println("\n\n\n")
|
|
println("Starting complex...")
|
|
|
|
pb := progress.NewProgressBar(mpb.WithWidth(64), mpb.WithRefreshRate(200*time.Millisecond))
|
|
pb.MainProcessInit()
|
|
|
|
defer func() {
|
|
pb.DeferMain()
|
|
}()
|
|
|
|
for i := 0; i < nbb; i++ {
|
|
if i > 0 && i%2 == 1 {
|
|
bar = append(bar, pb.NewBarKBits("KiB bar", tot, fmt.Sprintf(" | step %d | ", i), bar[i-1]))
|
|
} else if i > 0 && i%2 != 1 {
|
|
bar = append(bar, pb.NewBarKBits("KiB bar", 0, fmt.Sprintf(" | step %d | ", i), bar[i-1]))
|
|
} else {
|
|
bar = append(bar, pb.NewBarKBits("KiB bar", 0, fmt.Sprintf(" | step %d | ", i), nil))
|
|
}
|
|
}
|
|
|
|
for i := range bar {
|
|
if e := pb.NewWorker(); e != nil {
|
|
panic(e)
|
|
} else {
|
|
go func(nb int, sem libsem.Sem) {
|
|
defer func() {
|
|
pb.DeferWorker()
|
|
}()
|
|
|
|
rand.Seed(999)
|
|
|
|
for {
|
|
if nb > 0 && !bar[nb-1].Completed() {
|
|
time.Sleep(time.Second)
|
|
} else if bar[nb].Current() == 0 {
|
|
bar[nb].Reset(tot, 0)
|
|
}
|
|
|
|
if bar[nb].Current() < tot {
|
|
time.Sleep(time.Duration(rand.Intn(9)+1) * time.Millisecond)
|
|
bar[nb].Increment64(inc)
|
|
} else {
|
|
bar[nb].Done()
|
|
return
|
|
}
|
|
}
|
|
}(i, pb)
|
|
}
|
|
}
|
|
|
|
if e := pb.WaitAll(); e != nil {
|
|
panic(e)
|
|
}
|
|
|
|
time.Sleep(500 * time.Millisecond)
|
|
|
|
println("finish complex...")
|
|
}
|