コード例 #1
0
ファイル: daemon.go プロジェクト: harlo/streamtools
func (d *Daemon) Run(port string) {

	// start the ID Service
	idChan = make(chan string)
	go IDService(idChan)

	// start the library service
	blocks.BuildLibrary()

	// initialise the block maps
	d.blockMap = make(map[string]*blocks.Block)

	handler := rest.ResourceHandler{
		EnableRelaxedContentType: true,
	}

	//TODO: make this a _real_ restful API
	handler.SetRoutes(
		rest.Route{"GET", "/", d.rootHandler},
		rest.Route{"GET", "/library", d.libraryHandler},
		rest.Route{"GET", "/list", d.listHandler},
		rest.Route{"GET", "/create", d.createHandler},
		rest.Route{"GET", "/delete", d.deleteHandler},
		rest.Route{"GET", "/connect", d.connectHandler},
		rest.Route{"GET", "/blocks/:id/:route", d.routeHandler},
		rest.Route{"POST", "/blocks/:id/:route", d.routeHandler},
	)
	log.Println("starting stream tools on port", port)
	err := http.ListenAndServe(":"+port, &handler)
	if err != nil {
		log.Fatalf(err.Error())
	}
}
コード例 #2
0
ファイル: daemon.go プロジェクト: jpfairbanks/streamtools
func (d *Daemon) Run() {
	log.Printf("starting streamtools %s on port %s\n", VERSION, d.Port)
	// start the ID Service
	idChan = make(chan string)
	go IDService(idChan)

	// start the library service
	blocks.BuildLibrary()

	// initialise the block maps
	d.blockMap = make(map[string]*blocks.Block)

	handler := rest.ResourceHandler{
		EnableRelaxedContentType: true,
	}

	if len(d.Config) > 0 {
		err := d.importFile(d.Config)
		if err != nil {
			log.Println("could not import config file")
		}
	}

	//TODO: make this a _real_ restful API
	handler.SetRoutes(
		rest.Route{"GET", "/", d.rootHandler},
		rest.Route{"GET", "/static/main.css", d.cssHandler},
		rest.Route{"GET", "/static/d3.v3.min.js", d.d3Handler},
		rest.Route{"GET", "/static/main.js", d.mainjsHandler},
		rest.Route{"GET", "/static/jquery-2.1.0.min.js", d.jqueryHandler},
		rest.Route{"GET", "/static/underscore-min.js", d.underscoreHandler},
		rest.Route{"GET", "/library", d.libraryHandler},
		rest.Route{"GET", "/list", d.listHandler},
		rest.Route{"GET", "/create", d.createHandler},
		rest.Route{"GET", "/delete", d.deleteHandler},
		rest.Route{"GET", "/connect", d.connectHandler},
		rest.Route{"GET", "/blocks/:id/:route", d.routeHandler},
		rest.Route{"POST", "/blocks/:id/:route", d.routeHandler},
		rest.Route{"GET", "/export", d.exportHandler},
		rest.Route{"POST", "/import", d.importHandler},
	)

	err := http.ListenAndServe(":"+d.Port, &handler)
	if err != nil {
		log.Fatalf(err.Error())
	}
}