uplink/internal/servers/http/server.go

61 lines
1.3 KiB
Go
Raw Normal View History

2018-04-10 11:48:51 +00:00
package httpserver
import (
_ "git.icedream.tech/icedream/uplink/internal"
"git.icedream.tech/icedream/uplink/internal/authentication"
channels "git.icedream.tech/icedream/uplink/internal/channels"
_ "git.icedream.tech/icedream/uplink/internal/transcoders"
"net/http"
"github.com/gin-gonic/gin"
)
type Server struct {
Authenticator authentication.Authenticator
ChannelManager *channels.ChannelManager
}
func (server *Server) Run() {
httpServer := new(http.Server)
router := gin.New()
router.POST("/:channel", func(ctx *gin.Context) {
channel := server.ChannelManager.Channel(ctx.Param("channel"))
if channel == nil {
ctx.Status(404)
return
}
if user, password, ok := ctx.Request.BasicAuth(); ok {
if !server.Authenticator.VerifyUsernameAndPassword(channel, user, password) {
ctx.Status(401)
return
}
} else {
ctx.Status(401)
return
}
})
router.GET("/:channel", func(ctx *gin.Context) {
channel := server.ChannelManager.Channel(ctx.Param("channel"))
if channel == nil {
ctx.Status(404)
return
}
})
router.GET("/:channel/:stream", func(ctx *gin.Context) {
channel := server.ChannelManager.Channel(ctx.Param("channel"))
if channel == nil {
ctx.Status(404)
return
}
})
httpServer.Handler = router
httpServer.Addr = ":8000"
httpServer.ListenAndServe()
}