Beispiel #1
0
func main() {

	flag.BoolVar(&flags.verbose, "verbose", true,
		"Enable verbose debugging output")
	flag.Parse()
	if flags.verbose {
		verbose("Verbose mode activated")
	}

	readConfig()

	openState()

	notifyChan = make(chan Notification)
	ackChan = make(chan Ack)

	http.HandleFunc("/admin", admin)

	http.Handle("/", websocket.Handler(pushHandler))

	http.HandleFunc(gServerConfig.NotifyPrefix, notifyHandler)

	go deliverNotifications(notifyChan, ackChan)

	go func() {
		c := time.Tick(10 * time.Second)
		for now := range c {
			for uaid, client := range gServerState.ConnectedClients {
				if now.Sub(client.LastContact).Seconds() > 15 && client.Ip != "" {
					log.Println("Will wake up ", client.Ip, ". closing connection")
					disconnectUDPClient(uaid)
				}
			}
		}
	}()

	log.Println("Listening on", gServerConfig.Hostname+":"+gServerConfig.Port)

	var err error
	if gServerConfig.UseTLS {
		err = http.ListenAndServeTLS(gServerConfig.Hostname+":"+gServerConfig.Port,
			gServerConfig.CertFilename,
			gServerConfig.KeyFilename,
			nil)
	} else {
		for i := 0; i < 5; i++ {
			log.Println("This is a really unsafe way to run the push server.  Really.  Don't do this in production.")
		}
		err = http.ListenAndServe(gServerConfig.Hostname+":"+gServerConfig.Port, nil)
	}

	log.Println("Exiting... ", err)
}
Beispiel #2
0
func Cms() {

	serveSingle("/cms/", "assets/index.html")
	http.Handle("/cms/assets/", http.StripPrefix("/cms/assets", http.FileServer(http.Dir("./assets"))))

	router := mux.NewRouter()

	documentManager := new(DocumentManager)
	router.HandleFunc("/rest/document", BuildQuery(documentManager, "documents")).Methods("GET")
	router.HandleFunc("/rest/document", BuildPost(documentManager, "documents")).Methods("POST")
	router.HandleFunc("/rest/document/{id}", BuildGet(documentManager, "documents")).Methods("GET")
	router.HandleFunc("/rest/document/{id}", BuildPut(documentManager, "documents")).Methods("PUT")
	router.HandleFunc("/rest/document/{id}", BuildDelete(documentManager, "documents")).Methods("DELETE")

	documentTypeManager := new(DocumentTypeManager)
	router.HandleFunc("/rest/document-type", BuildQuery(documentTypeManager, "document-types")).Methods("GET")
	router.HandleFunc("/rest/document-type", BuildPost(documentTypeManager, "document-types")).Methods("POST")
	router.HandleFunc("/rest/document-type/{id}", BuildGet(documentTypeManager, "document-types")).Methods("GET")
	router.HandleFunc("/rest/document-type/{id}", BuildPut(documentTypeManager, "document-types")).Methods("PUT")
	router.HandleFunc("/rest/document-type/{id}", BuildDelete(documentTypeManager, "document-types")).Methods("DELETE")

	fileManager := new(FileManager)
	router.HandleFunc("/rest/file", BuildQuery(fileManager, "files")).Methods("GET")
	router.HandleFunc("/rest/file", PostFile).Methods("POST")
	router.HandleFunc("/rest/file/{id}", BuildGet(fileManager, "files")).Methods("GET")
	router.HandleFunc("/rest/file/{id}", BuildPut(fileManager, "files")).Methods("PUT")
	router.HandleFunc("/rest/file/{id}", BuildDelete(fileManager, "files")).Methods("DELETE")

	http.Handle("/notification", websocket.Handler(CreateNotificationServer()))

	http.Handle("/rest/", router)

	contentRouter := mux.NewRouter()
	contentRouter.HandleFunc("/content/{id}", GetContent).Methods("GET")
	http.Handle("/content/", contentRouter)
}
Beispiel #3
0
func ServeWebSocket() {
	http.Handle("/ws", websocket.Handler(controller.WsHandler))
	log.Fatal(http.ListenAndServe(Config["wshost"], nil))
}