Skip to content

Commit

Permalink
Fix linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
thomshutt authored and emranemran committed Sep 7, 2022
1 parent 7ade273 commit 576ae7a
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 19 deletions.
2 changes: 1 addition & 1 deletion api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func ListenAndServe(apiPort, mistPort int) error {
listen := fmt.Sprintf("0.0.0.0:%d", apiPort)
router := NewCatalystAPIRouter(mc)

config.Logger.Log(
_ = config.Logger.Log(
"msg", "Starting Catalyst API",
"version", config.Version,
"host", listen,
Expand Down
8 changes: 4 additions & 4 deletions clients/callback_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package clients

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"net/http/httptest"
"testing"
Expand All @@ -21,7 +21,7 @@ func TestItRetriesOnFailedCallbacks(t *testing.T) {
// Set up a dummy server to receive the callbacks
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check that we got the callback we're expecting
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
require.JSONEq(t, `{"completion_ratio":1, "status":"success", "timestamp": 123456789}`, string(body))

Expand Down Expand Up @@ -53,7 +53,7 @@ func TestItEventuallyStopsRetrying(t *testing.T) {
// Set up a dummy server to receive the callbacks
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check that we got the callback we're expecting
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
require.JSONEq(t, `{"completion_ratio":1, "status":"success", "timestamp": 123456789}`, string(body))

Expand All @@ -80,7 +80,7 @@ func TestTranscodeStatusErrorNotifcation(t *testing.T) {
// Set up a dummy server to receive the callbacks
svr := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check that we got the callback we're expecting
body, err := ioutil.ReadAll(r.Body)
body, err := io.ReadAll(r.Body)
require.NoError(t, err)
require.JSONEq(t, `{"completion_ratio": 0, "error": "something went wrong", "status":"error", "timestamp": 123456789}`, string(body))

Expand Down
8 changes: 4 additions & 4 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package errors

import (
"encoding/json"
"log"
"net/http"
"strings"

"github.com/livepeer/catalyst-api/config"
"github.com/xeipuuv/gojsonschema"
)

Expand All @@ -17,9 +17,9 @@ type apiError struct {

func writeHttpError(w http.ResponseWriter, msg string, status int, err error) apiError {
w.WriteHeader(status)
json.NewEncoder(w).Encode(map[string]string{"error": msg})
if err != nil {
log.Println(msg, err)

if err := json.NewEncoder(w).Encode(map[string]string{"error": msg}); err != nil {
_ = config.Logger.Log("msg", "error writing HTTP error", "http_error_msg", msg, "error", err)
}
return apiError{msg, status, err}
}
Expand Down
5 changes: 4 additions & 1 deletion handlers/ok.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import (
"net/http"

"github.com/julienschmidt/httprouter"
"github.com/livepeer/catalyst-api/config"
)

func (d *CatalystAPIHandlersCollection) Ok() httprouter.Handle {
return func(w http.ResponseWriter, req *http.Request, _ httprouter.Params) {
io.WriteString(w, "OK")
if _, err := io.WriteString(w, "OK"); err != nil {
_ = config.Logger.Log("error", "Failed to write HTTP response for "+req.URL.RawPath)
}
}
}
2 changes: 1 addition & 1 deletion handlers/transcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ func (d *CatalystAPIHandlersCollection) TranscodeSegment() httprouter.Handle {
if err := CallbackClient.SendTranscodeStatusError(transcodeRequest.CallbackUrl, "NYI - not yet implemented"); err != nil {
errors.WriteHTTPInternalServerError(w, "error send transcode error", err)
}
io.WriteString(w, "OK") // TODO later
_, _ = io.WriteString(w, "OK") // TODO later
}
}
31 changes: 26 additions & 5 deletions handlers/triggers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/julienschmidt/httprouter"
"github.com/livepeer/catalyst-api/clients"
"github.com/livepeer/catalyst-api/config"
"github.com/livepeer/catalyst-api/errors"
)

Expand Down Expand Up @@ -60,15 +61,31 @@ func (d *MistCallbackHandlersCollection) Trigger() httprouter.Handle {
// in place that we'll need
func stubTranscodingCallbacksForStudio(callbackURL string, callbackClient clients.CallbackClient) {
time.Sleep(5 * time.Second)
callbackClient.SendTranscodeStatus(callbackURL, clients.TranscodeStatusTranscoding, 0.3)
if err := callbackClient.SendTranscodeStatus(callbackURL, clients.TranscodeStatusTranscoding, 0.3); err != nil {
_ = config.Logger.Log("msg", "Error in stubTranscodingCallbacksForStudio", "err", err)
return
}

time.Sleep(5 * time.Second)
callbackClient.SendTranscodeStatus(callbackURL, clients.TranscodeStatusTranscoding, 0.6)
if err := callbackClient.SendTranscodeStatus(callbackURL, clients.TranscodeStatusTranscoding, 0.6); err != nil {
_ = config.Logger.Log("msg", "Error in stubTranscodingCallbacksForStudio", "err", err)
return
}

time.Sleep(5 * time.Second)
callbackClient.SendTranscodeStatus(callbackURL, clients.TranscodeStatusTranscoding, 0.9)
if err := callbackClient.SendTranscodeStatus(callbackURL, clients.TranscodeStatusTranscoding, 0.9); err != nil {
_ = config.Logger.Log("msg", "Error in stubTranscodingCallbacksForStudio", "err", err)
return
}

time.Sleep(5 * time.Second)
callbackClient.SendTranscodeStatus(callbackURL, clients.TranscodeStatusTranscoding, 1)
if err := callbackClient.SendTranscodeStatus(callbackURL, clients.TranscodeStatusTranscoding, 1); err != nil {
_ = config.Logger.Log("msg", "Error in stubTranscodingCallbacksForStudio", "err", err)
return
}

time.Sleep(5 * time.Second)
callbackClient.SendTranscodeStatusCompleted(
err := callbackClient.SendTranscodeStatusCompleted(
callbackURL,
clients.InputVideo{
Format: "mp4",
Expand Down Expand Up @@ -112,4 +129,8 @@ func stubTranscodingCallbacksForStudio(callbackURL string, callbackClient client
},
},
)
if err != nil {
_ = config.Logger.Log("msg", "Error sending Transcode Completed in stubTranscodingCallbacksForStudio", "err", err)
return
}
}
4 changes: 3 additions & 1 deletion handlers/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ func (d *CatalystAPIHandlersCollection) UploadVOD() httprouter.Handle {
errors.WriteHTTPInternalServerError(w, "Cannot send transcode status", err)
}

io.WriteString(w, fmt.Sprint(len(uploadVODRequest.OutputLocations)))
if _, err := io.WriteString(w, fmt.Sprint(len(uploadVODRequest.OutputLocations))); err != nil {
errors.WriteHTTPInternalServerError(w, "Cannot write output locations", err)
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions middleware/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ func LogRequest() func(httprouter.Handle) httprouter.Handle {
defer func() {
if err := recover(); err != nil {
errors.WriteHTTPInternalServerError(wrapped, "Internal Server Error", nil)
config.Logger.Log("err", err, "trace", debug.Stack())
_ = config.Logger.Log("err", err, "trace", debug.Stack())
}
}()

next(wrapped, r, ps)
config.Logger.Log(
_ = config.Logger.Log(
"remote", r.RemoteAddr,
"proto", r.Proto,
"method", r.Method,
Expand Down

0 comments on commit 576ae7a

Please sign in to comment.