Starting web interface
This commit is contained in:
parent
38fd0ab7cd
commit
7d585ce02e
10
main.go
10
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
|
||||
}
|
||||
|
|
|
@ -39,8 +39,7 @@ var youtubeVideoPatterns = []string{
|
|||
// YOUTUBE SERVICE
|
||||
// ---------------
|
||||
|
||||
type YouTube struct {
|
||||
}
|
||||
type YouTube struct {}
|
||||
|
||||
// Name of the service
|
||||
func (y YouTube) ServiceName() string {
|
||||
|
|
14
songqueue.go
14
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:]
|
||||
}
|
||||
|
|
35
web.go
Normal file
35
web.go
Normal 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)
|
||||
}
|
Reference in a new issue