parent
a13e1e75e2
commit
7361578412
@ -20,8 +20,7 @@ func GetLogs(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err := json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
}
|
||||
@ -39,8 +38,7 @@ func GetWarnings(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err := json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
}
|
||||
|
@ -65,8 +65,7 @@ func GetServerConfig(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
err := json.NewEncoder(w).Encode(response)
|
||||
if err != nil {
|
||||
if err := json.NewEncoder(w).Encode(response); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
}
|
||||
|
@ -18,8 +18,7 @@ func GetChatMessages(w http.ResponseWriter, r *http.Request) {
|
||||
case http.MethodGet:
|
||||
messages := core.GetAllChatMessages()
|
||||
|
||||
err := json.NewEncoder(w).Encode(messages)
|
||||
if err != nil {
|
||||
if err := json.NewEncoder(w).Encode(messages); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
default:
|
||||
|
@ -112,9 +112,7 @@ func handleScraperMetadataPage(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html")
|
||||
err = tmpl.Execute(w, metadata)
|
||||
|
||||
if err != nil {
|
||||
if err := tmpl.Execute(w, metadata); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
}
|
||||
|
@ -15,12 +15,12 @@ func GetStatus(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
status := core.GetStatus()
|
||||
response := webStatusResponse{
|
||||
Online: status.Online,
|
||||
ViewerCount: status.ViewerCount,
|
||||
LastConnectTime: status.LastConnectTime,
|
||||
Online: status.Online,
|
||||
ViewerCount: status.ViewerCount,
|
||||
LastConnectTime: status.LastConnectTime,
|
||||
LastDisconnectTime: status.LastDisconnectTime,
|
||||
VersionNumber: status.VersionNumber,
|
||||
StreamTitle: status.StreamTitle,
|
||||
VersionNumber: status.VersionNumber,
|
||||
StreamTitle: status.StreamTitle,
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
@ -30,12 +30,12 @@ func GetStatus(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
type webStatusResponse struct {
|
||||
Online bool `json:"online"`
|
||||
ViewerCount int `json:"viewerCount"`
|
||||
Online bool `json:"online"`
|
||||
ViewerCount int `json:"viewerCount"`
|
||||
|
||||
LastConnectTime utils.NullTime `json:"lastConnectTime"`
|
||||
LastDisconnectTime utils.NullTime `json:"lastDisconnectTime"`
|
||||
|
||||
VersionNumber string `json:"versionNumber"`
|
||||
StreamTitle string `json:"streamTitle"`
|
||||
}
|
||||
}
|
||||
|
@ -92,24 +92,20 @@ func (c *Client) listenWrite() {
|
||||
select {
|
||||
// Send a PING keepalive
|
||||
case msg := <-c.pingch:
|
||||
err := websocket.JSON.Send(c.ws, msg)
|
||||
if err != nil {
|
||||
if err := websocket.JSON.Send(c.ws, msg); err != nil {
|
||||
c.handleClientSocketError(err)
|
||||
}
|
||||
// send message to the client
|
||||
case msg := <-c.ch:
|
||||
err := websocket.JSON.Send(c.ws, msg)
|
||||
if err != nil {
|
||||
if err := websocket.JSON.Send(c.ws, msg); err != nil {
|
||||
c.handleClientSocketError(err)
|
||||
}
|
||||
case msg := <-c.usernameChangeChannel:
|
||||
err := websocket.JSON.Send(c.ws, msg)
|
||||
if err != nil {
|
||||
if err := websocket.JSON.Send(c.ws, msg); err != nil {
|
||||
c.handleClientSocketError(err)
|
||||
}
|
||||
case msg := <-c.userJoinedChannel:
|
||||
err := websocket.JSON.Send(c.ws, msg)
|
||||
if err != nil {
|
||||
if err := websocket.JSON.Send(c.ws, msg); err != nil {
|
||||
c.handleClientSocketError(err)
|
||||
}
|
||||
|
||||
@ -148,8 +144,7 @@ func (c *Client) listenRead() {
|
||||
// read data from websocket connection
|
||||
default:
|
||||
var data []byte
|
||||
err := websocket.Message.Receive(c.ws, &data)
|
||||
if err != nil {
|
||||
if err := websocket.Message.Receive(c.ws, &data); err != nil {
|
||||
if err == io.EOF {
|
||||
c.doneCh <- true
|
||||
return
|
||||
@ -162,10 +157,9 @@ func (c *Client) listenRead() {
|
||||
}
|
||||
|
||||
var messageTypeCheck map[string]interface{}
|
||||
err = json.Unmarshal(data, &messageTypeCheck)
|
||||
|
||||
// Bad messages should be thrown away
|
||||
if err != nil {
|
||||
if err := json.Unmarshal(data, &messageTypeCheck); err != nil {
|
||||
log.Debugln("Badly formatted message received from", c.Username, c.ws.Request().RemoteAddr)
|
||||
continue
|
||||
}
|
||||
@ -207,8 +201,7 @@ func (c *Client) userJoined(data []byte) {
|
||||
|
||||
func (c *Client) userChangedName(data []byte) {
|
||||
var msg models.NameChangeEvent
|
||||
err := json.Unmarshal(data, &msg)
|
||||
if err != nil {
|
||||
if err := json.Unmarshal(data, &msg); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
msg.Type = models.UserNameChanged
|
||||
@ -219,8 +212,7 @@ func (c *Client) userChangedName(data []byte) {
|
||||
|
||||
func (c *Client) chatMessageReceived(data []byte) {
|
||||
var msg models.ChatEvent
|
||||
err := json.Unmarshal(data, &msg)
|
||||
if err != nil {
|
||||
if err := json.Unmarshal(data, &msg); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
|
||||
|
@ -33,8 +33,7 @@ func createTable() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
_, err = stmt.Exec()
|
||||
if err != nil {
|
||||
if _, err := stmt.Exec(); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
}
|
||||
@ -51,12 +50,10 @@ func addMessage(message models.ChatEvent) {
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
_, err = stmt.Exec(message.ID, message.Author, message.Body, message.MessageType, 1, message.Timestamp)
|
||||
if err != nil {
|
||||
if _, err := stmt.Exec(message.ID, message.Author, message.Body, message.MessageType, 1, message.Timestamp); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
err = tx.Commit()
|
||||
if err != nil {
|
||||
if err := tx.Commit(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
@ -133,13 +130,12 @@ func saveMessageVisibility(messageIDs []string, visible bool) error {
|
||||
args[i+1] = id
|
||||
}
|
||||
|
||||
_, err = stmt.Exec(args...)
|
||||
if err != nil {
|
||||
if _, err := stmt.Exec(args...); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
if err = tx.Commit(); err != nil {
|
||||
if err := tx.Commit(); err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
@ -25,8 +25,7 @@ func createAccessTokensTable() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
_, err = stmt.Exec()
|
||||
if err != nil {
|
||||
if _, err := stmt.Exec(); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
}
|
||||
@ -48,7 +47,7 @@ func InsertToken(token string, name string, scopes []string) error {
|
||||
}
|
||||
defer stmt.Close()
|
||||
|
||||
if _, err = stmt.Exec(token, name, scopesString); err != nil {
|
||||
if _, err := stmt.Exec(token, name, scopesString); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,7 @@ func TestString(t *testing.T) {
|
||||
const testKey = "test string key"
|
||||
const testValue = "test string value"
|
||||
|
||||
err := _datastore.SetString(testKey, testValue)
|
||||
if err != nil {
|
||||
if err := _datastore.SetString(testKey, testValue); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,7 @@ func createWebhooksTable() {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer stmt.Close()
|
||||
_, err = stmt.Exec()
|
||||
if err != nil {
|
||||
if _, err = stmt.Exec(); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
}
|
||||
@ -126,8 +125,7 @@ func GetWebhooksForEvent(event models.EventType) []models.Webhook {
|
||||
for rows.Next() {
|
||||
var url string
|
||||
|
||||
err = rows.Scan(&url, &event)
|
||||
if err != nil {
|
||||
if err := rows.Scan(&url, &event); err != nil {
|
||||
log.Debugln(err)
|
||||
log.Error("There is a problem with the database.")
|
||||
break
|
||||
|
@ -32,16 +32,14 @@ func (s *LocalStorage) Setup() error {
|
||||
|
||||
// SegmentWritten is called when a single segment of video is written.
|
||||
func (s *LocalStorage) SegmentWritten(localFilePath string) {
|
||||
_, err := s.Save(localFilePath, 0)
|
||||
if err != nil {
|
||||
if _, err := s.Save(localFilePath, 0); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
}
|
||||
|
||||
// VariantPlaylistWritten is called when a variant hls playlist is written.
|
||||
func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) {
|
||||
_, err := s.Save(localFilePath, 0)
|
||||
if err != nil {
|
||||
if _, err := s.Save(localFilePath, 0); err != nil {
|
||||
log.Errorln(err)
|
||||
return
|
||||
}
|
||||
@ -49,8 +47,7 @@ func (s *LocalStorage) VariantPlaylistWritten(localFilePath string) {
|
||||
|
||||
// MasterPlaylistWritten is called when the master hls playlist is written.
|
||||
func (s *LocalStorage) MasterPlaylistWritten(localFilePath string) {
|
||||
_, err := s.Save(localFilePath, 0)
|
||||
if err != nil {
|
||||
if _, err := s.Save(localFilePath, 0); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
}
|
||||
|
@ -74,8 +74,7 @@ func (s *S3Storage) SegmentWritten(localFilePath string) {
|
||||
utils.StartPerformanceMonitor(performanceMonitorKey)
|
||||
|
||||
// Upload the segment
|
||||
_, err := s.Save(localFilePath, 0)
|
||||
if err != nil {
|
||||
if _, err := s.Save(localFilePath, 0); err != nil {
|
||||
log.Errorln(err)
|
||||
return
|
||||
}
|
||||
@ -92,8 +91,7 @@ func (s *S3Storage) SegmentWritten(localFilePath string) {
|
||||
// so the segments and the HLS playlist referencing
|
||||
// them are in sync.
|
||||
playlistPath := filepath.Join(filepath.Dir(localFilePath), "stream.m3u8")
|
||||
_, err = s.Save(playlistPath, 0)
|
||||
if err != nil {
|
||||
if _, err := s.Save(playlistPath, 0); err != nil {
|
||||
_queuedPlaylistUpdates[playlistPath] = playlistPath
|
||||
if pErr, ok := err.(*os.PathError); ok {
|
||||
log.Debugln(pErr.Path, "does not yet exist locally when trying to upload to S3 storage.")
|
||||
@ -108,8 +106,7 @@ func (s *S3Storage) VariantPlaylistWritten(localFilePath string) {
|
||||
// to make sure we're not referring to files in a playlist that don't
|
||||
// yet exist. See SegmentWritten.
|
||||
if _, ok := _queuedPlaylistUpdates[localFilePath]; ok {
|
||||
_, err := s.Save(localFilePath, 0)
|
||||
if err != nil {
|
||||
if _, err := s.Save(localFilePath, 0); err != nil {
|
||||
log.Errorln(err)
|
||||
_queuedPlaylistUpdates[localFilePath] = localFilePath
|
||||
}
|
||||
@ -120,8 +117,7 @@ func (s *S3Storage) VariantPlaylistWritten(localFilePath string) {
|
||||
// MasterPlaylistWritten is called when the master hls playlist is written.
|
||||
func (s *S3Storage) MasterPlaylistWritten(localFilePath string) {
|
||||
// Rewrite the playlist to use absolute remote S3 URLs
|
||||
err := s.rewriteRemotePlaylist(localFilePath)
|
||||
if err != nil {
|
||||
if err := s.rewriteRemotePlaylist(localFilePath); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
}
|
||||
@ -195,8 +191,7 @@ func (s *S3Storage) rewriteRemotePlaylist(filePath string) error {
|
||||
}
|
||||
|
||||
p := m3u8.NewMasterPlaylist()
|
||||
err = p.DecodeFrom(bufio.NewReader(f), false)
|
||||
if err != nil {
|
||||
if err := p.DecodeFrom(bufio.NewReader(f), false); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
|
||||
|
@ -94,12 +94,10 @@ func SetStreamAsDisconnected() {
|
||||
playlistFilePath := fmt.Sprintf(filepath.Join(config.PrivateHLSStoragePath, "%d/stream.m3u8"), index)
|
||||
segmentFilePath := fmt.Sprintf(filepath.Join(config.PrivateHLSStoragePath, "%d/%s"), index, offlineFilename)
|
||||
|
||||
err := utils.Copy(offlineFilePath, segmentFilePath)
|
||||
if err != nil {
|
||||
if err := utils.Copy(offlineFilePath, segmentFilePath); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
_, err = _storage.Save(segmentFilePath, 0)
|
||||
if err != nil {
|
||||
if _, err := _storage.Save(segmentFilePath, 0); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
if utils.DoesFileExists(playlistFilePath) {
|
||||
@ -119,16 +117,13 @@ func SetStreamAsDisconnected() {
|
||||
variantPlaylist.Segments = variantPlaylist.Segments[:len(variantPlaylist.Segments)]
|
||||
}
|
||||
|
||||
err = variantPlaylist.Append(offlineFilename, 8.0, "")
|
||||
if err != nil {
|
||||
if err := variantPlaylist.Append(offlineFilename, 8.0, ""); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
err = variantPlaylist.SetDiscontinuity()
|
||||
if err != nil {
|
||||
if err := variantPlaylist.SetDiscontinuity(); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
_, err = f.WriteAt(variantPlaylist.Encode().Bytes(), 0)
|
||||
if err != nil {
|
||||
if _, err := f.WriteAt(variantPlaylist.Encode().Bytes(), 0); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
} else {
|
||||
@ -138,8 +133,7 @@ func SetStreamAsDisconnected() {
|
||||
}
|
||||
|
||||
// If "offline" content gets changed then change the duration below
|
||||
err = p.Append(offlineFilename, 8.0, "")
|
||||
if err != nil {
|
||||
if err := p.Append(offlineFilename, 8.0, ""); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
|
||||
@ -149,13 +143,11 @@ func SetStreamAsDisconnected() {
|
||||
log.Errorln(err)
|
||||
}
|
||||
defer f.Close()
|
||||
_, err = f.Write(p.Encode().Bytes())
|
||||
if err != nil {
|
||||
if _, err := f.Write(p.Encode().Bytes()); err != nil {
|
||||
log.Errorln(err)
|
||||
}
|
||||
}
|
||||
_, err = _storage.Save(playlistFilePath, 0)
|
||||
if err != nil {
|
||||
if _, err := _storage.Save(playlistFilePath, 0); err != nil {
|
||||
log.Warnln(err)
|
||||
}
|
||||
}
|
||||
|
@ -74,8 +74,7 @@ func (s *FileWriterReceiverService) uploadHandler(w http.ResponseWriter, r *http
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
_, err = f.Write(data)
|
||||
if err != nil {
|
||||
if _, err := f.Write(data); err != nil {
|
||||
returnError(err, w)
|
||||
return
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ func (t *Transcoder) Start() {
|
||||
_commandExec = exec.Command("sh", "-c", command)
|
||||
|
||||
if t.stdin != nil {
|
||||
_commandExec.Stdin = t.stdin
|
||||
_commandExec.Stdin = t.stdin
|
||||
}
|
||||
|
||||
stdout, err := _commandExec.StderrPipe()
|
||||
@ -107,8 +107,7 @@ func (t *Transcoder) Start() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
err = _commandExec.Start()
|
||||
if err != nil {
|
||||
if err := _commandExec.Start(); err != nil {
|
||||
log.Errorln("Transcoder error. See ", logging.GetTranscoderLogFilePath(), " for full output to debug.")
|
||||
log.Panicln(err, command)
|
||||
}
|
||||
|
@ -94,31 +94,27 @@ func createVariantDirectories() {
|
||||
// Create private hls data dirs
|
||||
utils.CleanupDirectory(config.PublicHLSStoragePath)
|
||||
utils.CleanupDirectory(config.PrivateHLSStoragePath)
|
||||
|
||||
|
||||
if len(data.GetStreamOutputVariants()) != 0 {
|
||||
for index := range data.GetStreamOutputVariants() {
|
||||
err := os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777)
|
||||
if err != nil {
|
||||
if err := os.MkdirAll(path.Join(config.PrivateHLSStoragePath, strconv.Itoa(index)), 0777); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
dir := path.Join(config.PublicHLSStoragePath, strconv.Itoa(index))
|
||||
log.Traceln("Creating", dir)
|
||||
err = os.MkdirAll(dir, 0777)
|
||||
if err != nil {
|
||||
if err := os.MkdirAll(dir, 0777); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
dir := path.Join(config.PrivateHLSStoragePath, strconv.Itoa(0))
|
||||
log.Traceln("Creating", dir)
|
||||
err := os.MkdirAll(dir, 0777)
|
||||
if err != nil {
|
||||
if err := os.MkdirAll(dir, 0777); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
dir = path.Join(config.PublicHLSStoragePath, strconv.Itoa(0))
|
||||
log.Traceln("Creating", dir)
|
||||
err = os.MkdirAll(dir, 0777)
|
||||
if err != nil {
|
||||
if err := os.MkdirAll(dir, 0777); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}
|
||||
|
3
main.go
3
main.go
@ -75,8 +75,7 @@ func main() {
|
||||
|
||||
go metrics.Start()
|
||||
|
||||
err := data.SetupPersistence(config.DatabaseFilePath)
|
||||
if err != nil {
|
||||
if err := data.SetupPersistence(config.DatabaseFilePath); err != nil {
|
||||
log.Fatalln("failed to open database", err)
|
||||
}
|
||||
|
||||
|
@ -32,8 +32,7 @@ func Start() error {
|
||||
|
||||
// websocket chat server
|
||||
go func() {
|
||||
err := chat.Start()
|
||||
if err != nil {
|
||||
if err := chat.Start(); err != nil {
|
||||
log.Fatalln(err)
|
||||
}
|
||||
}()
|
||||
|
@ -5,8 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func TestCreateAccessToken(t *testing.T) {
|
||||
_, err := GenerateAccessToken()
|
||||
if err != nil {
|
||||
if _, err := GenerateAccessToken(); err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
}
|
||||
|
@ -49,8 +49,7 @@ func Restore(backupFile string, databaseFile string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = db.Exec(rawSql)
|
||||
if err != nil {
|
||||
if _, err := db.Exec(rawSql); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -161,8 +161,7 @@ func GetCacheDurationSecondsForPath(filePath string) int {
|
||||
}
|
||||
|
||||
func IsValidUrl(urlToTest string) bool {
|
||||
_, err := url.ParseRequestURI(urlToTest)
|
||||
if err != nil {
|
||||
if _, err := url.ParseRequestURI(urlToTest); err != nil {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -236,4 +235,4 @@ func CleanupDirectory(path string) {
|
||||
if err := os.MkdirAll(path, 0777); err != nil {
|
||||
log.Fatalln("Unable to create directory. Please check the ownership and permissions", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user