Skip to content

Commit

Permalink
Simplify logger calls
Browse files Browse the repository at this point in the history
  • Loading branch information
user committed Jul 12, 2021
1 parent 0f483d7 commit 04132d9
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 410 deletions.
84 changes: 42 additions & 42 deletions apiHTTPChannel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,25 @@ import (

//HTTPAPIServerStreamChannelCodec function return codec info struct
func HTTPAPIServerStreamChannelCodec(c *gin.Context) {
requestLogger := log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelCodec",
})

if !Storage.StreamChannelExist(c.Param("uuid"), c.Param("channel")) {
c.IndentedJSON(500, Message{Status: 0, Payload: ErrorStreamNotFound.Error()})
log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelCodec",
"call": "StreamChannelExist",
requestLogger.WithFields(logrus.Fields{
"call": "StreamChannelExist",
}).Errorln(ErrorStreamNotFound.Error())
return
}
codecs, err := Storage.StreamChannelCodecs(c.Param("uuid"), c.Param("channel"))
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelCodec",
"call": "StreamChannelCodec",
requestLogger.WithFields(logrus.Fields{
"call": "StreamChannelCodec",
}).Errorln(err.Error())
return
}
Expand Down Expand Up @@ -69,28 +68,27 @@ func HTTPAPIServerStreamChannelReload(c *gin.Context) {

//HTTPAPIServerStreamChannelEdit function edit stream
func HTTPAPIServerStreamChannelEdit(c *gin.Context) {
requestLogger := log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelEdit",
})

var payload ChannelST
err := c.BindJSON(&payload)
if err != nil {
c.IndentedJSON(400, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamEdit",
"call": "BindJSON",
requestLogger.WithFields(logrus.Fields{
"call": "BindJSON",
}).Errorln(err.Error())
return
}
err = Storage.StreamChannelEdit(c.Param("uuid"), c.Param("channel"), payload)
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelEdit",
"call": "StreamChannelEdit",
requestLogger.WithFields(logrus.Fields{
"call": "StreamChannelEdit",
}).Errorln(err.Error())
return
}
Expand All @@ -99,15 +97,18 @@ func HTTPAPIServerStreamChannelEdit(c *gin.Context) {

//HTTPAPIServerStreamChannelDelete function delete stream
func HTTPAPIServerStreamChannelDelete(c *gin.Context) {
requestLogger := log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelDelete",
})

err := Storage.StreamChannelDelete(c.Param("uuid"), c.Param("channel"))
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelDelete",
"call": "StreamChannelDelete",
requestLogger.WithFields(logrus.Fields{
"call": "StreamChannelDelete",
}).Errorln(err.Error())
return
}
Expand All @@ -116,28 +117,27 @@ func HTTPAPIServerStreamChannelDelete(c *gin.Context) {

//HTTPAPIServerStreamChannelAdd function add new stream
func HTTPAPIServerStreamChannelAdd(c *gin.Context) {
requestLogger := log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelAdd",
})

var payload ChannelST
err := c.BindJSON(&payload)
if err != nil {
c.IndentedJSON(400, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelAdd",
"call": "BindJSON",
requestLogger.WithFields(logrus.Fields{
"call": "BindJSON",
}).Errorln(err.Error())
return
}
err = Storage.StreamChannelAdd(c.Param("uuid"), c.Param("channel"), payload)
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_stream",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamChannelAdd",
"call": "StreamChannelAdd",
requestLogger.WithFields(logrus.Fields{
"call": "StreamChannelAdd",
}).Errorln(err.Error())
return
}
Expand Down
104 changes: 37 additions & 67 deletions apiHTTPHLS.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import (
"github.com/sirupsen/logrus"
)

//HTTPAPIServerStreamHLSTS send client m3u8 play list
//HTTPAPIServerStreamHLSM3U8 send client m3u8 play list
func HTTPAPIServerStreamHLSM3U8(c *gin.Context) {
requestLogger := log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSM3U8",
})

if !Storage.StreamChannelExist(c.Param("uuid"), c.Param("channel")) {
c.IndentedJSON(500, Message{Status: 0, Payload: ErrorStreamNotFound.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSM3U8",
"call": "StreamChannelExist",
requestLogger.WithFields(logrus.Fields{
"call": "StreamChannelExist",
}).Errorln(ErrorStreamNotFound.Error())
return
}
Expand All @@ -29,25 +32,17 @@ func HTTPAPIServerStreamHLSM3U8(c *gin.Context) {
index, seq, err := Storage.StreamHLSm3u8(c.Param("uuid"), c.Param("channel"))
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSM3U8",
"call": "StreamHLSm3u8",
requestLogger.WithFields(logrus.Fields{
"call": "StreamHLSm3u8",
}).Errorln(err.Error())
return
}
if seq >= 6 {
_, err := c.Writer.Write([]byte(index))
if err != nil {
c.IndentedJSON(400, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSM3U8",
"call": "Write",
requestLogger.WithFields(logrus.Fields{
"call": "Write",
}).Errorln(err.Error())
return
}
Expand All @@ -59,26 +54,25 @@ func HTTPAPIServerStreamHLSM3U8(c *gin.Context) {

//HTTPAPIServerStreamHLSTS send client ts segment
func HTTPAPIServerStreamHLSTS(c *gin.Context) {
requestLogger := log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSTS",
})

if !Storage.StreamChannelExist(c.Param("uuid"), c.Param("channel")) {
c.IndentedJSON(500, Message{Status: 0, Payload: ErrorStreamNotFound.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSTS",
"call": "StreamChannelExist",
requestLogger.WithFields(logrus.Fields{
"call": "StreamChannelExist",
}).Errorln(ErrorStreamNotFound.Error())
return
}
codecs, err := Storage.StreamChannelCodecs(c.Param("uuid"), c.Param("channel"))
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSTS",
"call": "StreamCodecs",
requestLogger.WithFields(logrus.Fields{
"call": "StreamCodecs",
}).Errorln(err.Error())
return
}
Expand All @@ -88,35 +82,23 @@ func HTTPAPIServerStreamHLSTS(c *gin.Context) {
err = Muxer.WriteHeader(codecs)
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSTS",
"call": "WriteHeader",
requestLogger.WithFields(logrus.Fields{
"call": "WriteHeader",
}).Errorln(err.Error())
return
}
seqData, err := Storage.StreamHLSTS(c.Param("uuid"), c.Param("channel"), stringToInt(c.Param("seq")))
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSTS",
"call": "StreamHLSTS",
requestLogger.WithFields(logrus.Fields{
"call": "StreamHLSTS",
}).Errorln(err.Error())
return
}
if len(seqData) == 0 {
c.IndentedJSON(500, Message{Status: 0, Payload: ErrorStreamNotHLSSegments.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSTS",
"call": "seqData",
requestLogger.WithFields(logrus.Fields{
"call": "seqData",
}).Errorln(ErrorStreamNotHLSSegments.Error())
return
}
Expand All @@ -125,37 +107,25 @@ func HTTPAPIServerStreamHLSTS(c *gin.Context) {
err = Muxer.WritePacket(*v)
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSTS",
"call": "WritePacket",
requestLogger.WithFields(logrus.Fields{
"call": "WritePacket",
}).Errorln(err.Error())
return
}
}
err = Muxer.WriteTrailer()
if err != nil {
c.IndentedJSON(500, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSTS",
"call": "WriteTrailer",
requestLogger.WithFields(logrus.Fields{
"call": "WriteTrailer",
}).Errorln(err.Error())
return
}
_, err = c.Writer.Write(outfile.Bytes())
if err != nil {
c.IndentedJSON(400, Message{Status: 0, Payload: err.Error()})
log.WithFields(logrus.Fields{
"module": "http_hls",
"stream": c.Param("uuid"),
"channel": c.Param("channel"),
"func": "HTTPAPIServerStreamHLSTS",
"call": "Write",
requestLogger.WithFields(logrus.Fields{
"call": "Write",
}).Errorln(err.Error())
return
}
Expand Down
Loading

0 comments on commit 04132d9

Please sign in to comment.