Пример #1
0
Файл: main.go Проект: Xe/gurren
func main() {
	sl, err := gurren.New([]string{"http://127.0.0.1:9200"}, "test", runtime.NumCPU())
	if err != nil {
		panic(err)
	}

	mux := routes.New()

	// Do handling here

	mux.Get("/", func(rw http.ResponseWriter, r *http.Request) {
		tpl, err := ace.Load("views/layout", "views/index", nil)
		if err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
			return
		}

		if err := tpl.Execute(rw, nil); err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
			return
		}
	})

	n := negroni.Classic()

	middleware.Inject(n)
	n.Use(sl)
	n.UseHandler(mux)

	n.Run(":3000")
}
Пример #2
0
Файл: main.go Проект: Xe/gurren
func main() {
	sl, err := gurren.New([]string{"http://127.0.0.1:9200"}, "test", 1)
	if err != nil {
		panic(err)
	}

	mux := http.NewServeMux()

	mux.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
		sl.Log(r, "/: Additional logging data")
		rw.Write([]byte("Hi there from static replies!"))
	})

	n := negroni.Classic()

	middleware.Inject(n)

	n.Use(sl)
	n.UseHandler(mux)

	n.Run(":3000")
}
Пример #3
0
func main() {
	sl, err := gurren.New([]string{"http://logging.hyperadmin.yochat.biz:9200"}, "test", runtime.NumCPU())
	if err != nil {
		panic(err)
	}

	re := render.New()

	mux := routes.New()

	mux.Get("/", func(rw http.ResponseWriter, r *http.Request) {
		doTemplate("views/index", rw, r, nil)
	})

	mux.Get("/rules", func(rw http.ResponseWriter, r *http.Request) {
		doTemplate("views/rules", rw, r, nil)
	})

	mux.Get("/chat", func(rw http.ResponseWriter, r *http.Request) {
		doTemplate("views/chat", rw, r, nil)
	})

	mux.Get("/tf2", func(rw http.ResponseWriter, r *http.Request) {
		s, err := fetchAndCache("tf2", sl, r, func() (interface{}, error) {
			return tf2.Query("10.0.0.5:27025", "cqcontrol")
		})
		if err != nil {
			handleError(rw, r, err)
		}

		doTemplate("views/tf2", rw, r, s)
	})

	mux.Get("/api/tf2.json", func(rw http.ResponseWriter, r *http.Request) {
		s, err := fetchAndCache("tf2", sl, r, func() (interface{}, error) {
			return tf2.Query("10.0.0.5:27025", "cqcontrol")
		})
		if err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
		}

		re.JSON(rw, http.StatusOK, s)
	})

	mux.Get("/minecraft", func(rw http.ResponseWriter, r *http.Request) {
		s, err := fetchAndCache("minecraft", sl, r, func() (interface{}, error) {
			return minecraft.Query("10.0.0.5", 25575, "swag")
		})
		if err != nil {
			handleError(rw, r, err)
		}

		doTemplate("views/minecraft", rw, r, s)
	})

	mux.Get("/api/minecraft.json", func(rw http.ResponseWriter, r *http.Request) {
		s, err := fetchAndCache("minecraft", sl, r, func() (interface{}, error) {
			return minecraft.Query("10.0.0.5", 25575, "swag")
		})
		if err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
		}

		re.JSON(rw, http.StatusOK, s)
	})

	mux.Get("/xonotic", func(rw http.ResponseWriter, r *http.Request) {
		c := xonotic.Dial("172.17.0.114", "26000")

		stats, err := fetchAndCache("xonotic", sl, r, func() (interface{}, error) {
			return c.Status()
		})
		if err != nil {
			handleError(rw, r, err)
		}

		doTemplate("views/xonotic", rw, r, stats)
	})

	mux.Get("/api/xonotic.json", func(rw http.ResponseWriter, r *http.Request) {
		c := xonotic.Dial("172.17.0.114", "26000")

		stats, err := fetchAndCache("xonotic", sl, r, func() (interface{}, error) {
			return c.Status()
		})
		if err != nil {
			http.Error(rw, err.Error(), http.StatusInternalServerError)
		}

		re.JSON(rw, http.StatusOK, stats)
	})

	mux.Get("/favicon.ico", func(rw http.ResponseWriter, r *http.Request) {
		http.Redirect(rw, r, "/favicon.png", 301)
	})

	n := negroni.Classic()

	middleware.Inject(n)
	n.Use(sl)
	n.UseHandler(mux)

	n.Run(":3000")
}