コード例 #1
0
ファイル: main.go プロジェクト: GrahamGoudeau/tchaik
func main() {
	flag.Parse()
	if listen == "" {
		flag.Usage()
		return
	}

	mediaFileSystem, artworkFileSystem, err := cmdflag.Stores()
	if err != nil {
		fmt.Println("error setting up stores:", err)
		os.Exit(1)
	}

	mediaFileSystem = &rootTraceFS{mediaFileSystem, "media"}
	artworkFileSystem = &rootTraceFS{artworkFileSystem, "artwork"}

	if debug {
		mediaFileSystem = store.LogFileSystem("Media", mediaFileSystem)
		artworkFileSystem = store.LogFileSystem("Artwork", artworkFileSystem)
	}

	if traceListenAddr != "" {
		fmt.Printf("Starting trace server on http://%v\n", traceListenAddr)
		go func() {
			log.Fatal(http.ListenAndServe(traceListenAddr, nil))
		}()
	}

	s := store.NewServer(listen)
	s.SetDefault(mediaFileSystem)
	s.SetFileSystem("artwork", artworkFileSystem)
	log.Fatal(s.Listen())
}
コード例 #2
0
ファイル: main.go プロジェクト: GrahamGoudeau/tchaik
func main() {
	flag.Parse()
	l, err := readLibrary()
	if err != nil {
		fmt.Printf("error: %v\n", err)
		os.Exit(1)
	}

	fmt.Printf("Building root collection...")
	root := buildRootCollection(l)
	fmt.Println("done.")

	fmt.Printf("Building artists filter...")
	artists := index.Filter(root, "Artist")
	fmt.Println("done.")

	fmt.Printf("Building recent index...")
	recent := index.Recent(root, 150)
	fmt.Println("done.")

	fmt.Printf("Building search index...")
	searcher := buildSearchIndex(root)
	fmt.Println("done.")

	fmt.Printf("Loading play history...")
	hs, err := history.NewStore(playHistoryPath)
	if err != nil {
		fmt.Printf("\nerror loading play history: %v", err)
		os.Exit(1)
	}
	fmt.Println("done.")

	// fmt.Printf("Loading playlists...")
	// ps, err := playlist.NewStore(playListPath)
	// if err != nil {
	// 	fmt.Printf("\nerror loading playlists: %v", err)
	// 	os.Exit(1)
	// }
	// fmt.Println("done")

	mediaFileSystem, artworkFileSystem, err := cmdflag.Stores()
	if err != nil {
		fmt.Println("error setting up stores:", err)
		os.Exit(1)
	}

	if debug {
		mediaFileSystem = store.LogFileSystem("Media", mediaFileSystem)
		artworkFileSystem = store.LogFileSystem("Artwork", artworkFileSystem)
	}

	if traceListenAddr != "" {
		fmt.Printf("Starting trace server on http://%v\n", traceListenAddr)
		go func() {
			log.Fatal(http.ListenAndServe(traceListenAddr, nil))
		}()
	}

	lib := Library{
		Library: l,
		collections: map[string]index.Collection{
			"Root": root,
		},
		filters: map[string][]index.FilterItem{
			"Artist": artists,
		},
		recent:   recent,
		searcher: searcher,
	}

	h := NewHandler(lib, hs, mediaFileSystem, artworkFileSystem)

	if certFile != "" && keyFile != "" {
		fmt.Printf("Web server is running on https://%v\n", listenAddr)
		fmt.Println("Quit the server with CTRL-C.")

		tlsConfig := &tls.Config{MinVersion: tls.VersionTLS10}
		server := &http.Server{Addr: listenAddr, Handler: h, TLSConfig: tlsConfig}
		log.Fatal(server.ListenAndServeTLS(certFile, keyFile))
	}

	fmt.Printf("Web server is running on http://%v\n", listenAddr)
	fmt.Println("Quit the server with CTRL-C.")

	log.Fatal(http.ListenAndServe(listenAddr, h))
}