Move utils to internal

This commit is contained in:
9seconds
2021-04-02 21:27:34 +03:00
parent 7b5cb8e14b
commit 2fe04c7c9b
6 changed files with 2 additions and 2 deletions
+24
View File
@@ -0,0 +1,24 @@
// +build !windows
package utils
import (
"fmt"
"golang.org/x/sys/unix"
)
func SetLimits() error {
rLimit := unix.Rlimit{}
if err := unix.Getrlimit(unix.RLIMIT_NOFILE, &rLimit); err != nil {
return fmt.Errorf("cannot get rlimit: %w", err)
}
rLimit.Cur = rLimit.Max
if err := unix.Setrlimit(unix.RLIMIT_NOFILE, &rLimit); err != nil {
return fmt.Errorf("cannot set rlimit: %w", err)
}
return nil
}
+7
View File
@@ -0,0 +1,7 @@
// +build windows
package utils
func SetLimits() error {
return nil
}
+25
View File
@@ -0,0 +1,25 @@
// +build !windows
package utils
import (
"context"
"os"
"os/signal"
"syscall"
)
func RootContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
go func() {
for range sigChan {
cancel()
}
}()
return ctx
}
+23
View File
@@ -0,0 +1,23 @@
// +build windows
package utils
import (
"context"
"os"
"os/signal"
)
func RootContext() context.Context {
ctx, cancel := context.WithCancel(context.Background())
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, os.Interrupt)
go func() {
for range sigChan {
cancel()
}
}()
return ctx
}