示例#1
0
文件: restapi.go 项目: hoxca/cinefade
func MapRoutes(bridge *hue.Bridge) {
	goweb.MapBefore(func(c context.Context) error {
		c.HttpResponseWriter().Header().Set("X-Custom-Header", "Goweb")
		return nil
	})

	goweb.MapAfter(func(c context.Context) error {
		return nil
	})

	goweb.Map("/", func(c context.Context) error {
		return goweb.Respond.With(c, 200, []byte("Welcome to the cinefade webapp\n"))
	})

	goweb.Map("/cinefade/{action}", func(c context.Context) error {
		action := c.PathValue("action")
		cinefadeSwitch(bridge, action)
		syslog.Infof("action %s was done by cinefade", action)
		return goweb.Respond.With(c, 200, []byte("Action '"+action+"' was done by cinefade\n"))
	})

	goweb.Map(func(c context.Context) error {
		return goweb.API.Respond(c, 404, nil, []string{"File not found"})
	})
}
示例#2
0
func main() {

	syslog.Openlog("cinefade", syslog.LOG_PID, syslog.LOG_USER)

	var action string
	flag.StringVar(&action, "action", "on", "lights on/off")
	flag.Parse()

	bridge := cinefade.GetBridge(false)
	cinefade.MapRoutes(bridge)

	// make a http server using the goweb.DefaultHttpHandler()
	s := &http.Server{
		Addr:           Address,
		Handler:        goweb.DefaultHttpHandler(),
		ReadTimeout:    10 * time.Second,
		WriteTimeout:   10 * time.Second,
		MaxHeaderBytes: 1 << 20,
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt)
	listener, listenErr := net.Listen("tcp", Address)
	syslog.Info("Server cinefade started")
	syslog.Infof("visit: %s", Address)

	if listenErr != nil {
		syslog.Critf("Could not listen: %s", listenErr)
		os.Exit(1)
	}

	go func() {
		for _ = range c {
			// sig is a ^C, handle it
			// stop the HTTP server
			syslog.Info("Stopping the cinefade server...")
			listener.Close()

			syslog.Info("Tearing down...")
			os.Exit(0)
		}
	}()

	syslog.Critf("Error in Serve: %s", s.Serve(listener))
	os.Exit(1)
}
示例#3
0
文件: main.go 项目: empereor/cvesync
func sync(feed nvd.CVE, cwes nvd.CWE, ts tracker.Tracker) {
	db := util.Get_DB(config.DBFile)
	defer db.Close()

	// Initialize tracker
	ts.Init()

	// Reverse the order as the xml feed is sorted from newest to oldest
	for i := len(feed.Entries) - 1; i >= 0; i-- {
		entry := feed.Entries[i]
		// Is any of the mentioned products on the blacklist?
		if !blist.Blacklisted(entry) {
			sync_entry(entry, db, cwes, ts)
		} else {
			syslog.Infof("Not syncing %v because one of the products were blacklisted", entry.Id)
		}
	}
}