Permalink
Browse files

Updated music collection (such as it is) for Go 1.

  • Loading branch information...
1 parent 106b010 commit 2114522e5f5a9fa14a95d02ec756e13c444e1bb6 @othiym23 othiym23 committed Mar 28, 2012
Showing with 19 additions and 24 deletions.
  1. +4 −9 Collections/Music/Makefile
  2. +14 −14 Collections/Music/go-music.go
  3. +1 −1 Collections/Music/package.json
View
@@ -1,9 +1,4 @@
-# Run this puppy with gomake if you don't want to set up your Go environment
-# explicitly.
-include $(GOROOT)/src/Make.inc
-
-TARG=go-music
-GOFILES=\
- go-music.go\
-
-include $(GOROOT)/src/Make.cmd
+# Without a makefile, Go would build this as a package and the resulting
+# binary would be 'Music', which is not what I want.
+go-music:
+ go build go-music.go
@@ -1,20 +1,20 @@
package main
import (
+ "encoding/json"
"fmt"
- "http"
"io"
- "json"
+ "launchpad.net/mgo"
+ "launchpad.net/mgo/bson"
"log"
"net"
+ "net/http"
+ "net/url"
"os"
"path"
"strconv"
"strings"
"time"
- "url"
- "launchpad.net/gobson/bson"
- "launchpad.net/mgo"
)
const (
@@ -90,7 +90,7 @@ func loadConfig() *ProcessInfo {
func mongoSession(pi *ProcessInfo) *mgo.Session {
config := pi.Mongo
- session, err := mgo.Mongo(config.Host + ":" + strconv.Itoa(config.Port))
+ session, err := mgo.Dial(config.Host + ":" + strconv.Itoa(config.Port))
if err != nil {
panic(err)
}
@@ -99,7 +99,7 @@ func mongoSession(pi *ProcessInfo) *mgo.Session {
}
func getDB(session *mgo.Session) mgo.Database {
- return session.DB(lockerDbName)
+ return *session.DB(lockerDbName)
}
func state(db *mgo.Database) func(http.ResponseWriter, *http.Request) {
@@ -120,27 +120,27 @@ func state(db *mgo.Database) func(http.ResponseWriter, *http.Request) {
}
// Need to find out what constitutes "ready"; hardcoded for now
- json.NewEncoder(w).Encode(CollectionState{1, count, time.Seconds(), last.Id.Hex()})
+ json.NewEncoder(w).Encode(CollectionState{1, count, time.Now().Unix(), last.Id.Hex()})
}
}
func resetCollection(db *mgo.Database, collection string, config *ProcessInfo) {
db.C(collection).DropCollection()
if _, err := http.Get(config.LockerUrl + "/Me/search/reindexForType?type=music"); err != nil {
- log.Println("Search reset error: " + err.String())
+ log.Println("Search reset error: " + err.Error())
}
}
func addLastfmTrack(collection *mgo.Collection, track *lastfmTrack) {
ids := make([]CandidateId, 1)
ids[0] = CandidateId{Type: "lastfm", Id: track.URL}
- duration, err := strconv.Atoi64(track.Duration)
+ duration, err := strconv.ParseInt(track.Duration, 10, 64)
if err != nil {
log.Println("Unable to convert duration to integer value.", track.Duration)
}
if err := collection.Insert(Track{IdBundle: ids, Name: track.Name, Artist: track.Artist.Name, Duration: duration}); err != nil {
- log.Println("Unable to insert into MongoDB: ", err.String())
+ log.Println("Unable to insert into MongoDB: ", err.Error())
}
}
@@ -183,7 +183,7 @@ func pullTracks(collection *mgo.Collection, config *ProcessInfo, source string)
func syncTracks(db *mgo.Database, config *ProcessInfo) {
collection := db.C(trackCollectionName)
for _, source := range trackSources {
- go pullTracks(&collection, config, source)
+ go pullTracks(collection, config, source)
}
}
@@ -232,7 +232,7 @@ func main() {
db := getDB(session)
defer session.Close()
- listener, err := net.Listen("tcp", net.JoinHostPort("127.0.0.1", strconv.Itoa64(config.Port)))
+ listener, err := net.Listen("tcp", net.JoinHostPort("127.0.0.1", strconv.FormatInt(config.Port, 10)))
if err != nil {
panic(err)
}
@@ -244,7 +244,7 @@ func main() {
panic(err)
}
- portnum, err := strconv.Atoi64(port)
+ portnum, err := strconv.ParseInt(port, 10, 64)
if err != nil {
panic(err)
}
@@ -39,4 +39,4 @@
},
"dependencies": {},
"devDependencies": {}
-}
+}

0 comments on commit 2114522

Please sign in to comment.