mirror of
https://github.com/datarhei/core.git
synced 2025-10-12 19:30:31 +08:00
Stop using deprecated functions
This commit is contained in:
@@ -6,7 +6,6 @@ package main
|
||||
import (
|
||||
gojson "encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"net/url"
|
||||
"os"
|
||||
@@ -503,7 +502,7 @@ func importV1(path string, cfg importConfig) (store.StoreData, error) {
|
||||
|
||||
r := store.NewStoreData()
|
||||
|
||||
jsondata, err := ioutil.ReadFile(path)
|
||||
jsondata, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return r, fmt.Errorf("failed to read data from %s: %w", path, err)
|
||||
}
|
||||
|
@@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
gojson "encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
@@ -51,7 +50,7 @@ func testV1Import(t *testing.T, v1Fixture, v4Fixture string, config importConfig
|
||||
require.Equal(t, nil, err)
|
||||
|
||||
// Read the wanted result
|
||||
wantdatav4, err := ioutil.ReadFile(v4Fixture)
|
||||
wantdatav4, err := os.ReadFile(v4Fixture)
|
||||
require.Equal(t, nil, err)
|
||||
|
||||
var wantv4 store.StoreData
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -58,7 +58,7 @@ func doRequest(url string) string {
|
||||
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package skills
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
@@ -16,14 +16,14 @@ type alsaCard struct {
|
||||
func DevicesALSA() ([]HWDevice, error) {
|
||||
devices := []HWDevice{}
|
||||
|
||||
content, err := ioutil.ReadFile("/proc/asound/cards")
|
||||
content, err := os.ReadFile("/proc/asound/cards")
|
||||
if err != nil {
|
||||
return devices, err
|
||||
}
|
||||
|
||||
cards := parseALSACards(content)
|
||||
|
||||
content, err = ioutil.ReadFile("/proc/asound/devices")
|
||||
content, err = os.ReadFile("/proc/asound/devices")
|
||||
if err != nil {
|
||||
return devices, err
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package resolver
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
@@ -79,7 +79,7 @@ func (r *queryResolver) playoutRequest(method, addr, path, contentType string, d
|
||||
defer response.Body.Close()
|
||||
|
||||
// Read the whole response
|
||||
data, err = ioutil.ReadAll(response.Body)
|
||||
data, err = io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"sort"
|
||||
@@ -96,7 +96,7 @@ func (h *MemFSHandler) PatchFile(c echo.Context) error {
|
||||
|
||||
req := c.Request()
|
||||
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusBadRequest, "Failed reading request body", "%s", err)
|
||||
}
|
||||
|
@@ -3,7 +3,7 @@ package api
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -59,7 +59,7 @@ func (h *PlayoutHandler) Status(c echo.Context) error {
|
||||
defer response.Body.Close()
|
||||
|
||||
// Read the whole response
|
||||
data, err := ioutil.ReadAll(response.Body)
|
||||
data, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusInternalServerError, "", "%s", err)
|
||||
}
|
||||
@@ -122,7 +122,7 @@ func (h *PlayoutHandler) Keyframe(c echo.Context) error {
|
||||
defer response.Body.Close()
|
||||
|
||||
// Read the whole response
|
||||
data, err := ioutil.ReadAll(response.Body)
|
||||
data, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusInternalServerError, "", "%s", err)
|
||||
}
|
||||
@@ -162,7 +162,7 @@ func (h *PlayoutHandler) EncodeErrorframe(c echo.Context) error {
|
||||
defer response.Body.Close()
|
||||
|
||||
// Read the whole response
|
||||
data, err := ioutil.ReadAll(response.Body)
|
||||
data, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusInternalServerError, "", "%s", err)
|
||||
}
|
||||
@@ -195,7 +195,7 @@ func (h *PlayoutHandler) SetErrorframe(c echo.Context) error {
|
||||
return api.Err(http.StatusNotFound, "Unknown process or input", "%s", err)
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(c.Request().Body)
|
||||
data, err := io.ReadAll(c.Request().Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusBadRequest, "Failed to read request body", "%s", err)
|
||||
}
|
||||
@@ -210,7 +210,7 @@ func (h *PlayoutHandler) SetErrorframe(c echo.Context) error {
|
||||
defer response.Body.Close()
|
||||
|
||||
// Read the whole response
|
||||
data, err = ioutil.ReadAll(response.Body)
|
||||
data, err = io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusInternalServerError, "", "%s", err)
|
||||
}
|
||||
@@ -249,7 +249,7 @@ func (h *PlayoutHandler) ReopenInput(c echo.Context) error {
|
||||
defer response.Body.Close()
|
||||
|
||||
// Read the whole response
|
||||
data, err := ioutil.ReadAll(response.Body)
|
||||
data, err := io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusInternalServerError, "", "%s", err)
|
||||
}
|
||||
@@ -281,7 +281,7 @@ func (h *PlayoutHandler) SetStream(c echo.Context) error {
|
||||
return api.Err(http.StatusNotFound, "Unknown process or input", "%s", err)
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(c.Request().Body)
|
||||
data, err := io.ReadAll(c.Request().Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusBadRequest, "Failed to read request body", "%s", err)
|
||||
}
|
||||
@@ -296,7 +296,7 @@ func (h *PlayoutHandler) SetStream(c echo.Context) error {
|
||||
defer response.Body.Close()
|
||||
|
||||
// Read the whole response
|
||||
data, err = ioutil.ReadAll(response.Body)
|
||||
data, err = io.ReadAll(response.Body)
|
||||
if err != nil {
|
||||
return api.Err(http.StatusInternalServerError, "", "%s", err)
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@ package util
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
||||
@@ -24,7 +24,7 @@ func ShouldBindJSONValidation(c echo.Context, obj interface{}, validate bool) er
|
||||
return fmt.Errorf("request doesn't contain JSON content")
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(req.Body)
|
||||
body, err := io.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import (
|
||||
"crypto"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -324,7 +324,7 @@ func (j *jwksImpl) refresh() (err error) {
|
||||
|
||||
// Read the raw JWKs from the body of the response.
|
||||
var jwksBytes []byte
|
||||
if jwksBytes, err = ioutil.ReadAll(resp.Body); err != nil {
|
||||
if jwksBytes, err = io.ReadAll(resp.Body); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@@ -4,7 +4,6 @@ import (
|
||||
"bufio"
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
@@ -108,7 +107,7 @@ func NewWithConfig(config Config) echo.MiddlewareFunc {
|
||||
// nothing is written to body or error is returned.
|
||||
// See issue #424, #407.
|
||||
res.Writer = rw
|
||||
w.Reset(ioutil.Discard)
|
||||
w.Reset(io.Discard)
|
||||
}
|
||||
w.Close()
|
||||
pool.Put(w)
|
||||
@@ -183,7 +182,7 @@ func (w *gzipResponseWriter) Push(target string, opts *http.PushOptions) error {
|
||||
func gzipPool(config Config) sync.Pool {
|
||||
return sync.Pool{
|
||||
New: func() interface{} {
|
||||
w, err := gzip.NewWriterLevel(ioutil.Discard, config.Level)
|
||||
w, err := gzip.NewWriterLevel(io.Discard, config.Level)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@@ -5,9 +5,9 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -57,7 +57,7 @@ func DummyEcho() *echo.Echo {
|
||||
router.HideBanner = true
|
||||
router.HidePort = true
|
||||
router.HTTPErrorHandler = errorhandler.HTTPErrorHandler
|
||||
router.Logger.SetOutput(ioutil.Discard)
|
||||
router.Logger.SetOutput(io.Discard)
|
||||
router.Validator = validator.New()
|
||||
|
||||
return router
|
||||
@@ -89,7 +89,7 @@ func CheckResponse(t *testing.T, res *http.Response) *Response {
|
||||
Code: res.StatusCode,
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
body, err := io.ReadAll(res.Body)
|
||||
require.Equal(t, nil, err)
|
||||
|
||||
if strings.Contains(res.Header.Get("Content-Type"), "application/json") {
|
||||
@@ -122,7 +122,7 @@ func Validate(t *testing.T, datatype, data interface{}) bool {
|
||||
}
|
||||
|
||||
func Read(t *testing.T, path string) io.Reader {
|
||||
data, err := ioutil.ReadFile(path)
|
||||
data, err := os.ReadFile(path)
|
||||
require.Equal(t, nil, err)
|
||||
|
||||
return bytes.NewReader(data)
|
||||
|
@@ -88,31 +88,37 @@ type Status struct {
|
||||
// States
|
||||
//
|
||||
// finished - Process has been stopped
|
||||
// starting - if process has been actively started or has been waiting for reconnect (order=start, reconnect=any)
|
||||
// finished - if process shall not reconnect (order=stop, reconnect=any)
|
||||
//
|
||||
// starting - if process has been actively started or has been waiting for reconnect (order=start, reconnect=any)
|
||||
// finished - if process shall not reconnect (order=stop, reconnect=any)
|
||||
//
|
||||
// starting - Process is about to start
|
||||
// finishing - if process should be immediately stopped (order=stop, reconnect=any)
|
||||
// running - if process could be started (order=start, reconnect=any)
|
||||
// failed - if process couldn't be started (e.g. binary not found) (order=start, reconnect=any)
|
||||
//
|
||||
// finishing - if process should be immediately stopped (order=stop, reconnect=any)
|
||||
// running - if process could be started (order=start, reconnect=any)
|
||||
// failed - if process couldn't be started (e.g. binary not found) (order=start, reconnect=any)
|
||||
//
|
||||
// running - Process is running
|
||||
// finished - if process exited normally (order=any, reconnect=any)
|
||||
// finishing - if process has been actively stopped (order=stop, reconnect=any)
|
||||
// failed - if process exited abnormally (order=any, reconnect=any)
|
||||
// killed - if process has been actively killed with SIGKILL (order=any, reconnect=any)
|
||||
//
|
||||
// finished - if process exited normally (order=any, reconnect=any)
|
||||
// finishing - if process has been actively stopped (order=stop, reconnect=any)
|
||||
// failed - if process exited abnormally (order=any, reconnect=any)
|
||||
// killed - if process has been actively killed with SIGKILL (order=any, reconnect=any)
|
||||
//
|
||||
// finishing - Process has been actively stopped and will be killed
|
||||
// finished - if process has been actively killed with SIGINT and ffmpeg exited normally (order=stop, reconnect=any)
|
||||
// killed - if process has been actively killed with SIGKILL (order=stop, reconnect=any)
|
||||
//
|
||||
// finished - if process has been actively killed with SIGINT and ffmpeg exited normally (order=stop, reconnect=any)
|
||||
// killed - if process has been actively killed with SIGKILL (order=stop, reconnect=any)
|
||||
//
|
||||
// failed - Process has been failed either by starting or during running
|
||||
// starting - if process has been waiting for reconnect (order=start, reconnect=true)
|
||||
// failed - if process shall not reconnect (order=any, reconnect=false)
|
||||
//
|
||||
// starting - if process has been waiting for reconnect (order=start, reconnect=true)
|
||||
// failed - if process shall not reconnect (order=any, reconnect=false)
|
||||
//
|
||||
// killed - Process has been stopped
|
||||
// starting - if process has been waiting for reconnect (order=start, reconnect=true)
|
||||
// killed - if process shall not reconnect (order=start, reconnect=false)
|
||||
//
|
||||
// starting - if process has been waiting for reconnect (order=start, reconnect=true)
|
||||
// killed - if process shall not reconnect (order=start, reconnect=false)
|
||||
type stateType string
|
||||
|
||||
const (
|
||||
|
@@ -98,7 +98,8 @@ func (p *process) cpuTimes() (*cpuTimesStat, error) {
|
||||
}
|
||||
|
||||
s := &cpuTimesStat{
|
||||
total: times.Total(),
|
||||
total: times.User + times.System + times.Idle + times.Nice + times.Iowait + times.Irq +
|
||||
times.Softirq + times.Steal + times.Guest + times.GuestNice,
|
||||
system: times.System,
|
||||
user: times.User,
|
||||
}
|
||||
|
@@ -285,7 +285,8 @@ func (u *util) cpuTimes() (*cpuTimesStat, error) {
|
||||
}
|
||||
|
||||
s := &cpuTimesStat{
|
||||
total: times[0].Total(),
|
||||
total: times[0].User + times[0].System + times[0].Idle + times[0].Nice + times[0].Iowait + times[0].Irq +
|
||||
times[0].Softirq + times[0].Steal + times[0].Guest + times[0].GuestNice,
|
||||
system: times[0].System,
|
||||
user: times[0].User,
|
||||
idle: times[0].Idle,
|
||||
|
@@ -3,7 +3,6 @@ package store
|
||||
import (
|
||||
gojson "encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
@@ -78,7 +77,7 @@ func (s *jsonStore) store(data StoreData) error {
|
||||
return err
|
||||
}
|
||||
|
||||
tmpfile, err := ioutil.TempFile(s.dir, s.filename)
|
||||
tmpfile, err := os.CreateTemp(s.dir, s.filename)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -122,7 +121,7 @@ func (s *jsonStore) load(version uint64) (StoreData, error) {
|
||||
return r, err
|
||||
}
|
||||
|
||||
jsondata, err := ioutil.ReadFile(filename)
|
||||
jsondata, err := os.ReadFile(filename)
|
||||
if err != nil {
|
||||
return r, err
|
||||
}
|
||||
|
@@ -6,7 +6,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -149,14 +148,14 @@ func (a *api) refreshAccessToken(refreshToken string) error {
|
||||
return errStatusAuthorization
|
||||
}
|
||||
|
||||
data, _ := ioutil.ReadAll(res.Body)
|
||||
data, _ := io.ReadAll(res.Body)
|
||||
return statusError{
|
||||
code: res.StatusCode,
|
||||
response: data,
|
||||
}
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
data, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return statusError{
|
||||
code: res.StatusCode,
|
||||
@@ -199,14 +198,14 @@ func (a *api) call(method, path string, body io.Reader) ([]byte, error) {
|
||||
return nil, errStatusAuthorization
|
||||
}
|
||||
|
||||
data, _ := ioutil.ReadAll(res.Body)
|
||||
data, _ := io.ReadAll(res.Body)
|
||||
return nil, statusError{
|
||||
code: res.StatusCode,
|
||||
response: data,
|
||||
}
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
data, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error reading response: %w", statusError{
|
||||
code: res.StatusCode,
|
||||
|
@@ -3,7 +3,6 @@ package session
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
@@ -461,7 +460,7 @@ func (c *collector) loadHistory(path string, data *history) {
|
||||
c.lock.persist.Lock()
|
||||
defer c.lock.persist.Unlock()
|
||||
|
||||
jsondata, err := ioutil.ReadFile(path)
|
||||
jsondata, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -489,7 +488,7 @@ func (c *collector) saveHistory(path string, data *history) {
|
||||
dir := filepath.Dir(path)
|
||||
filename := filepath.Base(path)
|
||||
|
||||
tmpfile, err := ioutil.TempFile(dir, filename)
|
||||
tmpfile, err := os.CreateTemp(dir, filename)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"sync"
|
||||
@@ -179,7 +179,7 @@ func (s *checker) check() error {
|
||||
return fmt.Errorf("request failed: %s", http.StatusText(res.StatusCode))
|
||||
}
|
||||
|
||||
body, err := ioutil.ReadAll(res.Body)
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error reading response: %w", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user