package main import ( "context" "flag" "github.com/schollz/progressbar/v3" "log" "net/url" "os" "path/filepath" ) func main() { config := Config{ Hostname: os.Getenv("GOKAPI_HOSTNAME"), APIKey: os.Getenv("GOKAPI_API_KEY"), ParallelChunks: 4, ChunkSize: 1024 * 100, } flag.Parse() hostUrl, err := url.Parse(config.Hostname) if err != nil { log.Fatal(err) } ctx := context.Background() client := newGokapiClient(hostUrl, config.APIKey) cnkr := newChunker(client, config.ParallelChunks, config.ChunkSize) for _, file := range flag.Args() { _, err := cnkr.UploadFile(ctx, file, progressBarReport(file)) if err != nil { log.Fatal(err) } } } func progressBarReport(filename string) func(cr ChunkReport) { var pr *progressbar.ProgressBar return func(cr ChunkReport) { if cr.UploadedChunks == 0 && pr == nil { pr = progressbar.DefaultBytes(cr.TotalSize, filepath.Base(filename)) } pr.Set(int(cr.UploadedBytes)) } }