Skip to content

Commit

Permalink
Mass fixing linting
Browse files Browse the repository at this point in the history
  • Loading branch information
COMTOP1 committed Jan 5, 2025
1 parent 92bef18 commit cdae05a
Show file tree
Hide file tree
Showing 29 changed files with 196 additions and 136 deletions.
1 change: 1 addition & 0 deletions common/transporter/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

type (
// TransporterUnique is sent with an ID in order to be returned and sorted
//nolint:revive
TransporterUnique struct {
// ID is the unique code used to identify a request
ID string `json:"id" mapstructure:"id"`
Expand Down
1 change: 1 addition & 0 deletions common/wsMessages/special/specialWsMessages.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:revive
package wsMessages

type SpecialWSMessage string
Expand Down
1 change: 1 addition & 0 deletions common/wsMessages/wsMessages.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//nolint:revive
package wsMessages

type WSMessage string
Expand Down
15 changes: 11 additions & 4 deletions server/helper/getBody.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package helper

import (
"context"
"io"
"log"
"net/http"
Expand All @@ -9,17 +10,23 @@ import (
)

func GetBody(url string) (body string, err error) {
ctx, cancelFunc := context.WithTimeout(context.Background(), 2*time.Second)
defer cancelFunc()

client := http.Client{
Timeout: 5 * time.Second,
}
response, err := client.Get(url)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
log.Printf("failed to creating request: %v", err)
return
}
response, err := client.Do(req)
if err != nil {
log.Printf("failed to get http: %+v", err)
return
}
defer func(Body io.ReadCloser) {
_ = Body.Close()
}(response.Body)
defer response.Body.Close()

buf := new(strings.Builder)
_, err = io.Copy(buf, response.Body)
Expand Down
17 changes: 9 additions & 8 deletions server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,19 @@ var embeddedFiles embed.FS

// main function is the start and the root for the website
func main() {
if strings.Contains(os.Args[0], "/var/folders") || strings.Contains(os.Args[0], "/tmp/go") || strings.Contains(os.Args[0], "./streamer") {
if len(os.Args) > 2 {
log.Fatalf("Arguments error")
}
for i := 0; i < len(os.Args)-1; i++ {
os.Args[i] = os.Args[i+1]
}
} else {
if !strings.Contains(os.Args[0], "/var/folders") && !strings.Contains(os.Args[0], "/tmp/go") && !strings.Contains(os.Args[0], "./streamer") {
if len(os.Args) > 1 {
log.Fatalf("Arguments error")
}
}

if len(os.Args) > 2 {
log.Fatalf("Arguments error")
}
for i := 0; i < len(os.Args)-1; i++ {
os.Args[i] = os.Args[i+1]
}

if os.Args[0] == "-v" {
verbose = true
} else {
Expand Down
6 changes: 4 additions & 2 deletions server/store/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package store

import (
"fmt"
"github.com/ystv/streamer/server/storage"
"google.golang.org/protobuf/proto"
"log"
"os"
"sync"
"time"

"github.com/ystv/streamer/server/storage"

"google.golang.org/protobuf/proto"
)

// FileBackend Applications: apps, Prefix: prefix
Expand Down
49 changes: 25 additions & 24 deletions server/store/store.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package store

import (
"errors"
"fmt"

"github.com/ystv/streamer/server/storage"
Expand All @@ -23,16 +24,16 @@ func (store *Store) GetStreams() ([]*storage.Stream, error) {
if err != nil {
return nil, err
}
return streamer.Stream, err
return streamer.GetStream(), err
}

func (store *Store) FindStream(unique string) (*storage.Stream, error) {
streamer, err := store.Get()
if err != nil {
return nil, err
}
for _, c1 := range streamer.Stream {
if c1.Stream == unique {
for _, c1 := range streamer.GetStream() {
if c1.GetStream() == unique {
return c1, nil
}
}
Expand All @@ -45,9 +46,9 @@ func (store *Store) AddStream(stream *storage.Stream) (*storage.Stream, error) {
return nil, err
}

for _, c := range streamer.Stream {
if c.Stream == stream.Stream {
return nil, fmt.Errorf("unable to add stream duplicate id for AddStream")
for _, c := range streamer.GetStream() {
if c.GetStream() == stream.GetStream() {
return nil, errors.New("unable to add stream duplicate id for AddStream")
}
}

Expand All @@ -66,25 +67,25 @@ func (store *Store) DeleteStream(unique string) error {
return err
}

s := streamer.Stream
s := streamer.GetStream()
found := false
var index int
var v *storage.Stream
for index, v = range s {
if v.Stream == unique {
if v.GetStream() == unique {
found = true
break
}
}

if found {
copy(s[index:], s[index+1:]) // Shift a[i+1:] left one index
s[len(s)-1] = nil // Erase last element (write zero value)
streamer.Stream = s[:len(s)-1] // Truncate slice
} else {
return fmt.Errorf("stream not found for DeleteStream")
if !found {
return errors.New("stream not found for DeleteStream")
}

copy(s[index:], s[index+1:]) // Shift a[i+1:] left one index
s[len(s)-1] = nil // Erase last element (write zero value)
streamer.Stream = s[:len(s)-1] // Truncate slice

if err = store.backend.Write(streamer); err != nil {
return err
}
Expand All @@ -97,16 +98,16 @@ func (store *Store) GetStored() ([]*storage.Stored, error) {
if err != nil {
return nil, fmt.Errorf("failed to get stored from GetStored: %w", err)
}
return streamer.Stored, nil
return streamer.GetStored(), nil
}

func (store *Store) FindStored(unique string) (*storage.Stored, error) {
streamer, err := store.Get()
if err != nil {
return nil, fmt.Errorf("failed to get stored from ")
return nil, fmt.Errorf("failed to get stored from FindStored: %w", err)
}
for _, c1 := range streamer.Stored {
if c1.Stream == unique {
for _, c1 := range streamer.GetStored() {
if c1.GetStream() == unique {
return c1, nil
}
}
Expand All @@ -119,9 +120,9 @@ func (store *Store) AddStored(stored *storage.Stored) (*storage.Stored, error) {
return nil, err
}

for _, c := range streamer.Stored {
if c.Stream == stored.Stream {
return nil, fmt.Errorf("unable to add stored duplicate id for AddStored")
for _, c := range streamer.GetStored() {
if c.GetStream() == stored.GetStream() {
return nil, errors.New("unable to add stored duplicate id for AddStored")
}
}

Expand All @@ -140,12 +141,12 @@ func (store *Store) DeleteStored(unique string) error {
return err
}

s := streamer.Stored
s := streamer.GetStored()
found := false
var index int
var v *storage.Stored
for index, v = range s {
if v.Stream == unique {
if v.GetStream() == unique {
found = true
break
}
Expand All @@ -156,7 +157,7 @@ func (store *Store) DeleteStored(unique string) error {
s[len(s)-1] = nil // Erase last element (write zero value)
streamer.Stored = s[:len(s)-1] // Truncate slice
} else {
return fmt.Errorf("stream not found for DeleteStored")
return errors.New("stream not found for DeleteStored")
}

if err = store.backend.Write(streamer); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion server/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (t *Templater) RenderTemplate(w io.Writer, data interface{}, mainTmpl Templ

if err != nil {
log.Printf("failed to get templates for template(RenderTemplate): %+v", err)
return fmt.Errorf("failed to get templates for template(RenderTemplate): %+v", err)
return fmt.Errorf("failed to get templates for template(RenderTemplate): %w", err)
}

return t1.Execute(w, data)
Expand Down
5 changes: 3 additions & 2 deletions server/views/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package views

import (
"fmt"
"github.com/labstack/echo/v4"
"log"
"net/http"

"github.com/labstack/echo/v4"
)

// DeleteFunc will delete the saved stream before it can start
Expand All @@ -22,7 +23,7 @@ func (v *Views) DeleteFunc(c echo.Context) error {
unique := c.FormValue("unique")
if len(unique) != 10 {
log.Printf("unique key invalid: %s", unique)
response.Error = fmt.Sprintf("unique key invalid: %s", unique)
response.Error = "unique key invalid: " + unique
return c.JSON(http.StatusOK, response)
}

Expand Down
3 changes: 2 additions & 1 deletion server/views/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package views

import (
"errors"
"github.com/ystv/streamer/server/templates"

"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"

"github.com/ystv/streamer/server/templates"
)

func (v *Views) CustomHTTPErrorHandler(err error, c echo.Context) {
Expand Down
4 changes: 2 additions & 2 deletions server/views/forceRemove.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (v *Views) ForceRemoveFunc(c echo.Context) error {
unique := c.Param("unique")
if len(unique) != 10 {
log.Printf("unique key invalid: %s", unique)
response.Error = fmt.Sprintf("unique key invalid: %s", unique)
response.Error = "unique key invalid: " + unique
return c.JSON(http.StatusOK, response)
}

Expand Down Expand Up @@ -73,7 +73,7 @@ func (v *Views) ForceRemoveFunc(c echo.Context) error {
Unique: unique,
}

if len(stream.Recording) > 0 && rec {
if len(stream.GetRecording()) > 0 && rec {
recorderTransporter := transporter
var wsResponse commonTransporter.ResponseTransporter
wsResponse, err = v.wsHelper(server.Recorder, recorderTransporter)
Expand Down
8 changes: 4 additions & 4 deletions server/views/generateUnique.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func (v *Views) generateUnique() (string, error) {

streams1, err := v.store.GetStreams()
if err != nil {
return "", fmt.Errorf("failed to get streams: %+v", err)
return "", fmt.Errorf("failed to get streams: %w", err)
}

if len(streams1) == 0 {
break
}

for _, s := range streams1 {
if s.Stream == string(b) {
if s.GetStream() == string(b) {
loop = true
break
}
Expand All @@ -34,15 +34,15 @@ func (v *Views) generateUnique() (string, error) {

stored, err := v.store.GetStored()
if err != nil {
return "", fmt.Errorf("failed to get stored: %+v", err)
return "", fmt.Errorf("failed to get stored: %w", err)
}

if len(stored) == 0 {
break
}

for _, s := range stored {
if s.Stream == string(b) {
if s.GetStream() == string(b) {
loop = true
break
}
Expand Down
Loading

0 comments on commit cdae05a

Please sign in to comment.