From 7d585ce02ec0fa147ce0705579e0101acb2cc2a7 Mon Sep 17 00:00:00 2001 From: MichaelOultram Date: Tue, 28 Jul 2015 14:56:20 +0100 Subject: [PATCH] Starting web interface --- main.go | 10 ++++++---- service_youtube.go | 3 +-- songqueue.go | 14 ++++++++------ web.go | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 50 insertions(+), 12 deletions(-) create mode 100644 web.go diff --git a/main.go b/main.go index 6ef1170..bc8d710 100644 --- a/main.go +++ b/main.go @@ -13,9 +13,9 @@ import ( "fmt" "os" "os/user" + "reflect" "strings" "time" - "reflect" "github.com/layeh/gopus" "github.com/layeh/gumble/gumble" @@ -148,8 +148,8 @@ func Verbose(msg string) { } func isNil(a interface{}) bool { - defer func() { recover() }() - return a == nil || reflect.ValueOf(a).IsNil() + defer func() { recover() }() + return a == nil || reflect.ValueOf(a).IsNil() } // dj variable declaration. This is done outside of main() to allow global use. @@ -228,7 +228,9 @@ func main() { if err := dj.client.Connect(); err != nil { fmt.Printf("Could not connect to Mumble server at %s:%s.\n", address, port) os.Exit(1) - } + } + + Webserver() <-dj.keepAlive } diff --git a/service_youtube.go b/service_youtube.go index b951164..4c60cd0 100644 --- a/service_youtube.go +++ b/service_youtube.go @@ -39,8 +39,7 @@ var youtubeVideoPatterns = []string{ // YOUTUBE SERVICE // --------------- -type YouTube struct { -} +type YouTube struct {} // Name of the service func (y YouTube) ServiceName() string { diff --git a/songqueue.go b/songqueue.go index 67db542..f1bdc1c 100644 --- a/songqueue.go +++ b/songqueue.go @@ -42,14 +42,16 @@ func (q *SongQueue) CurrentSong() Song { // NextSong moves to the next Song in SongQueue. NextSong() removes the first Song in the queue. func (q *SongQueue) NextSong() { - if s, err := q.PeekNext(); err == nil { - if !isNil(q.CurrentSong().Playlist()) && !isNil(s.Playlist()) { - if q.CurrentSong().Playlist().ID() != s.Playlist().ID() { - q.CurrentSong().Playlist().DeleteSkippers() + if !isNil(q.CurrentSong().Playlist()) { + if s, err := q.PeekNext(); err == nil { + if !isNil(s.Playlist()) { + if q.CurrentSong().Playlist().ID() != s.Playlist().ID() { + q.CurrentSong().Playlist().DeleteSkippers() + } } + } else { + q.CurrentSong().Playlist().DeleteSkippers() } - } else { - q.CurrentSong().Playlist().DeleteSkippers() } q.queue = q.queue[1:] } diff --git a/web.go b/web.go new file mode 100644 index 0000000..1e9d95f --- /dev/null +++ b/web.go @@ -0,0 +1,35 @@ +package mumbledj + +import ( + "fmt" + "io/ioutil" + "net/http" +) + +type Page struct { + Title string + Body []byte +} + +func (p *Page) save() error { + filename := p.Title + ".txt" + return ioutil.WriteFile(filename, p.Body, 0600) +} + +func loadPage(title string) (*Page, error) { + filename := title + ".txt" + body, err := ioutil.ReadFile(filename) + if err != nil { + return nil, err + } + return &Page{Title: title, Body: body}, nil +} + +func handler(w http.ResponseWriter, r *http.Request) { + fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:]) +} + +func Webserver(){ + http.HandleFunc("/", handler) + http.ListenAndServe(":8080", nil) +}