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

10
main.go
View file

@ -13,9 +13,9 @@ import (
"fmt" "fmt"
"os" "os"
"os/user" "os/user"
"reflect"
"strings" "strings"
"time" "time"
"reflect"
"github.com/layeh/gopus" "github.com/layeh/gopus"
"github.com/layeh/gumble/gumble" "github.com/layeh/gumble/gumble"
@ -148,8 +148,8 @@ func Verbose(msg string) {
} }
func isNil(a interface{}) bool { func isNil(a interface{}) bool {
defer func() { recover() }() defer func() { recover() }()
return a == nil || reflect.ValueOf(a).IsNil() return a == nil || reflect.ValueOf(a).IsNil()
} }
// dj variable declaration. This is done outside of main() to allow global use. // 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 { if err := dj.client.Connect(); err != nil {
fmt.Printf("Could not connect to Mumble server at %s:%s.\n", address, port) fmt.Printf("Could not connect to Mumble server at %s:%s.\n", address, port)
os.Exit(1) os.Exit(1)
} }
Webserver()
<-dj.keepAlive <-dj.keepAlive
} }

View file

@ -39,8 +39,7 @@ var youtubeVideoPatterns = []string{
// YOUTUBE SERVICE // YOUTUBE SERVICE
// --------------- // ---------------
type YouTube struct { type YouTube struct {}
}
// Name of the service // Name of the service
func (y YouTube) ServiceName() string { 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. // NextSong moves to the next Song in SongQueue. NextSong() removes the first Song in the queue.
func (q *SongQueue) NextSong() { func (q *SongQueue) NextSong() {
if s, err := q.PeekNext(); err == nil { if !isNil(q.CurrentSong().Playlist()) {
if !isNil(q.CurrentSong().Playlist()) && !isNil(s.Playlist()) { if s, err := q.PeekNext(); err == nil {
if q.CurrentSong().Playlist().ID() != s.Playlist().ID() { if !isNil(s.Playlist()) {
q.CurrentSong().Playlist().DeleteSkippers() 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:] 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)
}