Beispiel #1
0
func main() {
	flag.Parse()
	if *h {
		flag.Usage()
		return
	}

	messageStore, err := pgstore.OpenMessageStore(*dbUser, *dbPasswd, *dbHost, *dbName)
	if err != nil {
		log.Fatalf("error opening message store: %v", err)
	}
	blobStore, err := pgstore.OpenBlobStore(*dbUser, *dbPasswd, *dbHost, *dbName)
	if err != nil {
		log.Fatalf("error opening blob store: %v", err)
	}

	if *initPgStore {
		if err := messageStore.InitTables(); err != nil {
			log.Fatalf("Error initializing message tables: %v", err)
		}

		if err := blobStore.InitTables(); err != nil {
			log.Fatalf("Error initializing blob tables: %v", err)
		}

		log.Printf("Tables initialized")
		return
	}

	server := pandora.Server{
		BlobStore:    blobStore,
		MessageStore: messageStore,
	}

	handler := &webui.Handler{
		Api: pandorahttp.Handler{
			Server:     &server,
			AllowAdmin: true,
		},
	}

	if *static == "!usegas" {
		handler.DefaultStatic()
	} else {
		handler.Static = http.FileServer(http.Dir(*static))
	}

	log.Printf("starting server at %v", *addr)
	if err = http.ListenAndServe(*addr, handler); err != nil {
		log.Fatalf("error starting server: %v", err)
	}
}
Beispiel #2
0
func mustCreateServer() *pandora.Server {
	bs, err := pgstore.OpenBlobStore("pandora", "pandora", "localhost", "pandora")
	if err != nil {
		panic(err)
	}

	ms, err := pgstore.OpenMessageStore("pandora", "pandora", "localhost", "pandora")
	if err != nil {
		panic(err)
	}
	if err := ms.DeleteMessages(); err != nil {
		panic(err)
	}
	return &pandora.Server{
		BlobStore:    bs,
		MessageStore: ms,
	}
}