Starting web interface

This commit is contained in:
MichaelOultram 2015-07-28 14:56:20 +01:00
parent 38fd0ab7cd
commit 7d585ce02e
4 changed files with 50 additions and 12 deletions

View file

@ -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.
@ -230,5 +230,7 @@ func main() {
os.Exit(1)
}
Webserver()
<-dj.keepAlive
}

View file

@ -39,8 +39,7 @@ var youtubeVideoPatterns = []string{
// YOUTUBE SERVICE
// ---------------
type YouTube struct {
}
type YouTube struct {}
// Name of the service
func (y YouTube) ServiceName() string {

View file

@ -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:]
}

35
web.go Normal file
View file

@ -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)
}