func main() {
	nodeMap = make(map[uint64]string)
	FirstNode := "http://localhost:3000/"
	SecondNode := "http://localhost:3001/"
	ThirdNode := "http://localhost:3002/"

	keys = append(keys, murmur3.Sum64([]byte(FirstNode)))
	keys = append(keys, murmur3.Sum64([]byte(SecondNode)))
	keys = append(keys, murmur3.Sum64([]byte(ThirdNode)))

	keys.Sort()
	fmt.Println("Keys array is : ", keys)

	for _, element := range keys {
		switch element {

		case murmur3.Sum64([]byte(FirstNode)):
			nodeMap[element] = FirstNode
		case murmur3.Sum64([]byte(SecondNode)):
			nodeMap[element] = SecondNode
		case murmur3.Sum64([]byte(ThirdNode)):
			nodeMap[element] = ThirdNode
		}

	}

	mux := routes.New()
	mux.Put("/keys/:keyID/:value", PutValue)
	mux.Get("/keys/:keyID", RetrieveValue)

	http.Handle("/", mux)
	http.ListenAndServe(":8080", nil)

}
Beispiel #2
0
func init() {

	mux := routes.New()
	mux.Get("/blog/", ViewArticleHandler)
	mux.Get("/blog/:year/:month/:day/:title", ViewArticleHandler)
	mux.Get("/blog/tag/:tag", TagHandler)
	mux.Get("/blog/archive/:year/:month", ArchiveHandler)

	//mux.Get("/blog/comment/post", SaveCommentHandler)
	mux.Post("/blog/comment", SaveCommentHandler)

	mux.Get("/admin", AdminHandler)
	mux.Get("/admin/article/post", SaveArticleHandler)
	mux.Get("/admin/article/edit", EditArticleHandler)
	mux.Get("/admin/article/update", UpdateArticleHandler)
	mux.Get("/admin/article/delete", DeleteArticleHandler)
	mux.Get("/admin/article/preview", PreViewArticleHandler)
	mux.Get("/admin/comment", ListCommentHandler)
	mux.Del("/admin/comment", DeleteCommentHandler)
	//mux.Get("/admin/comment/delete", DeleteCommentHandler)

	mux.Get("/feed/atom", RssHandler)
	mux.Get("/feed", RssHandler)
	mux.Get("/rss.xml", RssHandler)

	mux.Get("/sitemap.xml", SitemapHandler)
	mux.Get("/sitemap", SitemapHandler)
	mux.Get("/release", ReleaseHandler)
	mux.Get("/", IndexHandler)

	http.Handle("/", mux)
}
Beispiel #3
0
func Project() http.Handler {
	mux := routes.New()

	mux.Get("/project/:name([0-9a-z]+)", getProject)

	return mux
}
Beispiel #4
0
Datei: main.go Projekt: 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")
}
Beispiel #5
0
func main() {
	//http.HandleFunc("/", common.Index) //设置访问的路由
	//http.HandleFunc("/login", common.Login) //设置访问的路由
	//http.HandleFunc("/upload", common.Upload) //设置访问的路由
	//http.HandleFunc("/reg", user.Reg) //设置访问的路由
	//http.HandleFunc("/test", common.test) //设置访问的路由

	http.Handle("/upload/", http.StripPrefix("/upload/", http.FileServer(http.Dir("upload"))))
	http.Handle("/assets/", http.StripPrefix("/assets/", http.FileServer(http.Dir("assets"))))
	mux := routes.New()
	mux.Get("/user/:uid", user.Show)
	mux.Get("/", common.Index) //设置访问的路由

	mux.Get("/login", common.Login)  //设置访问的路由
	mux.Post("/login", common.Login) //设置访问的路由

	mux.Get("/upload", common.Upload)  //设置访问的路由
	mux.Post("/upload", common.Upload) //设置访问的路由

	mux.Get("/reg", user.Reg)  //设置访问的路由
	mux.Post("/reg", user.Reg) //设置访问的路由

	http.Handle("/", mux)
	err := http.ListenAndServe(":8080", nil) //设置监听的端口

	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
Beispiel #6
0
func main() {
	port := fmt.Sprintf(":%d", pubConfig.Port)
	mux := routes.New()
	mux.Get("/", GetHelp)
	mux.Get("/repo", ListRepos)
	mux.Get("/repo/:ID", GetRepo)
	//either refresh or add
	mux.Post("/repo", AddRepo)
	//either refresh or modify (especially enable/disable)
	mux.Post("/repo/:ID", ModifyRepo)

	mux.Get("/case", ListCases)
	//TODO: add group/name in the future
	mux.Get("/case/:ID", GetCase)
	mux.Get("/case/:ID/report", GetCaseReport)

	//The task api is not necessary now, just used for web in the future.
	//Add a new task by the case id
	mux.Get("/task", ListTasks)
	//Add task : turn a case into a task, but donnot send to scheduler
	mux.Post("/task", AddTask)
	mux.Get("/task/:TaskID", GetTaskStatus)
	mux.Get("/task/:TaskID/report", GetTaskReport)
	// apply/deploy/run/collect/destroy
	mux.Post("/task/:TaskID", PostTaskAction)

	http.Handle("/", mux)
	logrus.Infof("Listen to port ", port)
	err := http.ListenAndServe(port, nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
Beispiel #7
0
func main() {
	initDB()
	mux := routes.New()
	mux.Get("/api/devices", getDevices)
	http.Handle("/", mux)
	http.ListenAndServe(":8088", nil)
}
Beispiel #8
0
// main is the entry point for lagann
func main() {
	flag.Parse()

	client = etcd.NewClient([]string{"http://" + *etcdmachine + ":4001"})

	routing := http.NewServeMux()
	usermux := routes.New()

	n := negroni.Classic()
	n.UseHandler(routing)

	routing.HandleFunc(constants.ROOT_MUXPATH, root)
	routing.HandleFunc(constants.REGISTER_URL, register)
	routing.HandleFunc(constants.LOGIN_URL, login)

	usermux.Post(constants.APP_CREATE_URL, createApp)
	usermux.Post(constants.APP_SHARING_URL, addSharing)

	auth, _ := auth.NewAuth("http://"+*etcdmachine+":4001", constants.ETCD_LAGANN_AUTHKEYS)

	routing.Handle(constants.USER_MUXPATH, negroni.New(
		auth,
		negroni.Wrap(usermux),
	))

	n.Run(":3000")
}
Beispiel #9
0
func main() {

	mux := routes.New()
	mux.Get("/api/:name", requestHandler)
	http.Handle("/", mux)
	http.ListenAndServe(":9091", nil)

}
Beispiel #10
0
func main() {
	mux := routes.New()
	mux.Get("/:last/:first", Whoami)
	pwd, _ := os.Getwd()
	mux.Static("/static", pwd)
	http.Handle("/", mux)
	http.ListenAndServe(":8088", nil)
}
Beispiel #11
0
func init() {
	mux := routes.New()

	mux.Get("/users", func(res http.ResponseWriter, req *http.Request) {
		fmt.Fprintf(res, "GET: /users")
	})

	http.Handle("/users", mux)
}
Beispiel #12
0
func main() {
	mux := routes.New()
	mux.Get("/user/:uid", getuser)
	mux.Post("/user/", adduser)
	mux.Del("/user/:uid", deleteuser)
	mux.Put("/user/:uid", modifyuser)
	http.Handle("/", mux)
	http.ListenAndServe(":8088", nil)
}
func main() {
	mux := routes.New()
	mux.Post("/locations/", addLocation)
	mux.Get("/locations/:locationId", findLocation)
	mux.Put("/locations/:locationId", updateLocation)
	mux.Del("/locations/:locationId", deleteLocation)
	http.Handle("/", mux)
	http.ListenAndServe(":8088", nil)
}
Beispiel #14
0
func main() {
	mux := routes.New()
	mux.Get("/", handler)
	mux.Get("/rentals/:id", getRentalHandler)
	//http.HandleFunc("/view/", viewHandler)
	//http.HandleFunc("/", handler)
	http.Handle("/", mux)
	http.ListenAndServe(":3000", nil)
}
Beispiel #15
0
func main() {

	mux := routes.New()
	mux.Get("/:user/:topic", getSlide)
	mux.Post("/:user/:topic", postSlide)
	mux.Put("/:user/:topic", putSlide)
	http.Handle("/", mux)
	http.ListenAndServe(":7777", nil)
}
Beispiel #16
0
func main() {
	Println("启动 REST 服务器")
	mux := routes.New()
	mux.Get("/user/:uid", getuser)
	mux.Post("/user/:uid", edituser)
	mux.Del("/user/:uid", deluser)
	mux.Put("/user/:uid", adduser)
	Handle("/", mux)
	ListenAndServe(":8088", nil)
}
Beispiel #17
0
func main() {
	mux := routes.New()
	mux.Get("/articlelist/:page", ArticleListHandler)
	mux.Get("/article/:title", LoadArticleHandler)
	mux.Post("/insert/", InsertArticleHandler)
	http.Handle("/", mux)
	err := http.ListenAndServe(":7070", nil)
	if err != nil {
		log.Fatal(err)
	}
}
func main() {

	mux := routes.New()
	mux.Put("/keys/:keyID/:value", insertValue)

	mux.Get("/keys/:keyID", getValue)
	mux.Get("/keys", getAllValues)

	http.Handle("/", mux)
	http.ListenAndServe(":3002", nil)
}
func main() {

	mux := routes.New()
	mux.Put("/keys/:keyID/:value", PutValue)

	mux.Get("/keys/:keyID", RetrieveSingleValue)
	mux.Get("/keys", RetrieveAllValues)

	http.Handle("/", mux)
	http.ListenAndServe(":3001", nil)
}
Beispiel #20
0
// Benchmark_Routes runs a benchmark against our custom Mux using the
// default settings.
func Benchmark_Routes(b *testing.B) {

	handler := routes.New()
	handler.Get("/person/:last/:first", HandlerOk)

	for i := 0; i < b.N; i++ {
		r, _ := http.NewRequest("GET", "/person/anderson/thomas?learn=kungfu", nil)
		w := httptest.NewRecorder()
		handler.ServeHTTP(w, r)
	}

}
Beispiel #21
0
func main() {
	defer database.Close()

	api := routes.New()
	points.InitMux(api)
	http.HandleFunc("/api/v1.0/", SubHandler("api/v1.0", api))

	admin := http.FileServer(http.Dir("admin"))
	http.Handle("/admin/", SubHandler("admin", admin))

	http.ListenAndServe(":"+os.Getenv("PORT"), nil)
}
Beispiel #22
0
func main() {
	mux := routes.New()
	mux.Post("/profile", CreateProfile)
	mux.Get("/profile/:email", GetProfile)
	mux.Del("/profile/:email", DeleteProfile)
	mux.Put("/profile/:email", UpdateProfile)

	http.Handle("/", mux)
	users = make(map[string]User)
	log.Println("Listening...")
	http.ListenAndServe(":3000", nil)
}
func main() {
	mux := routes.New()

	lc := controllers.NewLocationController(getSession())

	mux.Get("/locations/:location_id", lc.GetLocation)
	mux.Post("/locations", lc.AddLocation)
	mux.Del("/locations/:location_id", lc.DeleteLocation)
	mux.Put("/locations/:location_id", lc.UpdateLocation)
	http.Handle("/", mux)
	http.ListenAndServe(":8088", nil)
}
Beispiel #24
0
func main() {

	mux := routes.New()
	mux.Get("/api2/:name", HelloRoutes)
	/*
		gorillaroute := mux.NewRouter()
		gorillaroute.HandleFunc("/api/{user:[0-9]+}", Hello)
		http.Handle("/", gorillaroute)
	*/
	http.Handle("/", mux)
	http.ListenAndServe(":8080", nil)

}
Beispiel #25
0
// New [...]
func New(port, env string, db *models.DB) (*APIServer, error) {
	a := &APIServer{Port: port, Env: env, DB: db}

	mux := routes.New()
	mux.Get("/ping", a.PingHandler)
	mux.Get("/relevant/:user", a.RecommendHandler)
	mux.Post("/collect/:user", a.CollectHandler)

	http.Handle("/", mux)
	go a.Run()

	return a, nil
}
func main() {
	mux := routes.New()
	mux.Post("/locations/", addLocation)
	mux.Get("/locations/:locationID", findLocation)
	mux.Put("/locations/:locationID", updateLocation)
	mux.Del("/locations/:locationID", deleteLocation)

	mux.Post("/trips/", planTrip)
	mux.Put("/trips/:tripID/request", requestTrip)
	mux.Get("/trips/:tripID", getTripDetails)

	http.Handle("/", mux)
	http.ListenAndServe(":8088", nil)
}
Beispiel #27
0
func main() {
	fmt.Println("Start app")
	//	//websocket
	//	http.Handle("/", websocket.Handler(Echo))
	//	if err := http.ListenAndServe(":4001", nil); err != nil {
	//		log.Fatal("ListenAndServe:", err)
	//	}

	//restful
	mux := routes.New()
	mux.Get("/user/:uid", GetUser)
	http.Handle("/", mux)
	http.ListenAndServe(":4002", nil)
}
func main() {
	//http.HandleFunc("/", hello)
	mux := routes.New()
	//mux.Get("/:last/:first", whoami)
	mux.Get("/users", getusers)
	mux.Get("/users/:id", getuser)
	mux.Put("/users/:id", modifyuser)
	mux.Del("/users/:id", deleteuser)
	mux.Post("/users/", adduser)
	http.Handle("/", mux)

	err := http.ListenAndServe(":9090", nil)
	if err != nil {
		log.Fatal("ListenAndServe:", err)
	}
}
Beispiel #29
0
func main() {
	var port string
	port = fmt.Sprintf(":%d", pubConfig.Port)

	mux := routes.New()
	mux.Post("/task", ReceiveTask)
	mux.Post("/task/:ID", PostTaskAction)
	mux.Get("/task/:ID/report", GetTaskReport)

	http.Handle("/", mux)
	logrus.Infof("Start to listen %v", port)
	err := http.ListenAndServe(port, nil)
	if err != nil {
		logrus.Fatalf("ListenAndServe: %v ", err)
	}
}
func main() {
	log.Printf("Starting on port: 8088...")

	mux := routes.New()
	//get led
	mux.Get("/led/", getleds)
	mux.Get("/led/:led/", getled)
	mux.Post("/led/:led/:ledstatus/", modifyled)
	mux.Post("/led/", test)
	//mux.Del("/user/:uid", deleteuser)
	//mux.Put("/user/", adduser)

	log.Printf("Started on port: 8088...")

	http.Handle("/", mux)
	http.ListenAndServe(":8088", nil)
}