fix: change tape error

This commit is contained in:
Samuel N Cui
2022-12-13 17:00:04 +08:00
parent f87ec06af6
commit 8ccecd8017
26 changed files with 501 additions and 273 deletions

42
tools/context.go Normal file
View File

@@ -0,0 +1,42 @@
package tools
import (
"context"
"log"
"os"
"os/signal"
"syscall"
"time"
)
type noTimeout struct {
ctx context.Context
}
func (c noTimeout) Deadline() (time.Time, bool) { return time.Time{}, false }
func (c noTimeout) Done() <-chan struct{} { return nil }
func (c noTimeout) Err() error { return nil }
func (c noTimeout) Value(key interface{}) interface{} { return c.ctx.Value(key) }
// WithoutCancel returns a context that is never canceled.
func WithoutTimeout(ctx context.Context) context.Context {
return noTimeout{ctx: ctx}
}
var (
ShutdownContext context.Context
)
func init() {
c := make(chan os.Signal, 1)
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
bgctx, cancel := context.WithCancel(context.Background())
go func() {
oscall := <-c
log.Printf("system call: %+v", oscall)
cancel()
}()
ShutdownContext = bgctx
}

12
tools/error.go Normal file
View File

@@ -0,0 +1,12 @@
package tools
import (
"github.com/hashicorp/go-multierror"
)
func AppendError(err, e error) error {
if err != nil {
return multierror.Append(err, e)
}
return e
}

19
tools/working.go Normal file
View File

@@ -0,0 +1,19 @@
package tools
import "sync"
var (
wg sync.WaitGroup
)
func Working() {
wg.Add(1)
}
func Done() {
wg.Done()
}
func Wait() {
wg.Wait()
}