Exemplo n.º 1
0
func AddRoutes(r martini.Router) {
	r.Group("/api/v1", func(r martini.Router) {
		addNeedRoutes(r)
		addResourceRoutes(r)
		addStaffRoutes(r)
	}, MapCodec)
}
Exemplo n.º 2
0
Arquivo: api.go Projeto: vozhyk-/gohan
// mapChildNamespaceRoute sets a handler returning a dictionary of resources
// supported by a certain API version identified by the given namespace
func mapChildNamespaceRoute(route martini.Router, namespace *schema.Namespace) {
	log.Debug("[Path] %s", namespace.GetFullPrefix())
	route.Get(
		namespace.GetFullPrefix(),
		func(w http.ResponseWriter, r *http.Request, p martini.Params, context martini.Context) {
			resources := []schema.NamespaceResource{}
			for _, s := range schema.GetManager().Schemas() {
				if s.NamespaceID == namespace.ID {
					resources = append(resources, schema.NamespaceResource{
						Links: []schema.Link{
							schema.Link{
								Href: s.GetPluralURL(),
								Rel:  "self",
							},
						},
						Name:       s.Singular,
						Collection: s.Plural,
					})
				}
			}

			routes.ServeJson(w, map[string][]schema.NamespaceResource{"resources": resources})
		},
	)
}
Exemplo n.º 3
0
func addStaffRoutes(r martini.Router) {
	r.Group("/staff", func(r martini.Router) {
		r.Get("", func() string {
			return "Staff stuff?"
		})
	}, ensureStaffMember)
}
Exemplo n.º 4
0
func (tr *TaskRouter) Register(r martini.Router) {
	r.Get("", tr.GetAllTasks)
	r.Post("", tr.CreateTask)
	r.Get("/:id", tr.GetTask)
	r.Put("/:id", tr.CreateTask)
	r.Delete("/:id", tr.CancelTask)
}
Exemplo n.º 5
0
Arquivo: api.go Projeto: vozhyk-/gohan
// mapTopLevelNamespaceRoute maps route listing available subnamespaces (versions)
// for a top-level namespace
func mapTopLevelNamespaceRoute(route martini.Router, namespace *schema.Namespace) {
	log.Debug("[Path] %s/", namespace.GetFullPrefix())
	route.Get(
		namespace.GetFullPrefix()+"/",
		func(w http.ResponseWriter, r *http.Request, p martini.Params, context martini.Context) {
			versions := []schema.Version{}
			for _, childNamespace := range schema.GetManager().Namespaces() {
				if childNamespace.Parent == namespace.ID {
					versions = append(versions, schema.Version{
						Status: "SUPPORTED",
						ID:     childNamespace.Prefix,
						Links: []schema.Link{
							schema.Link{
								Href: childNamespace.GetFullPrefix() + "/",
								Rel:  "self",
							},
						},
					})
				}
			}

			if len(versions) != 0 {
				versions[len(versions)-1].Status = "CURRENT"
			}

			routes.ServeJson(w, map[string][]schema.Version{"versions": versions})
		})
}
Exemplo n.º 6
0
func CreateJobsRoutes(r martini.Router) {
	jobrunner.Start() // optional: jobrunner.Start(pool int, concurrent int) (10, 1)
	jobrunner.Schedule("@every 5s", ReminderEmails{})
	jobrunner.Schedule("@every 10s", ReminderEmails{})
	entries := jobrunner.Entries()
	fmt.Println(entries[len(entries)-1].ID)
	r.Get("/status", requestJobs)
}
Exemplo n.º 7
0
func setup(router martini.Router) {
	router.Get("/user/:id", controllers.UserGet)

	router.Put("/user/:id",
		binding.Json(models.User{}),
		binding.ErrorHandler,
		controllers.UserPut)
}
Exemplo n.º 8
0
func initCurrencyApi(r martini.Router) {
	r.Group("/currencies", func(r martini.Router) {
		r.Get("", func() string {
			var _, body, _ = request.Get("http://api.fixer.io/latest?base=USD").End()
			return body
		})
	})
}
Exemplo n.º 9
0
func InitApplicationsRoutes(r martini.Router) {
	r.Group("/admin/applications", func(router martini.Router) {
		router.Get("/get/:id", getApplication)
		router.Get("/list", getApplications)
		router.Post("/create", createApplications)
		router.Post("/update", updateApplications)
		router.Post("/delete/:id", deleteApplication)
	})
}
Exemplo n.º 10
0
func (lr *ThingRouter) Register(r martini.Router) {

	r.Get("", lr.GetAll)
	r.Get("/:id", lr.GetThing)
	r.Put("/:id", lr.PutThing)
	r.Put("/:id/location", lr.PutThingLocation)
	r.Delete("/:id", lr.DeleteThing)

}
Exemplo n.º 11
0
func addResourceRoutes(r martini.Router) {
	r.Get("/resources", func() string {
		return "All my resources"
	})

	r.Get("/resources/:id", func(p martini.Params) string {
		return "Resources(" + p["id"] + ")"
	})
}
Exemplo n.º 12
0
func InitRolesRoutes(r martini.Router) {
	r.Group("/admin/roles", func(router martini.Router) {
		router.Get("/get/:id", getRole)
		router.Get("/list", getRoles)
		router.Get("/application/:appId", getRolesByApplication)
		router.Post("/create", createRoles)
		router.Post("/update", updateRoles)
		router.Post("/delete/:id", deleteRole)
	})
}
Exemplo n.º 13
0
func InitGroupsRoutes(r martini.Router) {
	r.Group("/admin/groups", func(router martini.Router) {
		router.Get("/get/:id", getGroup)
		router.Get("/list", getGroups)
		router.Get("/application/:appId", getGroupsByApplication)
		router.Post("/create", createGroups)
		router.Post("/update", updateGroups)
		router.Post("/delete/:id", deleteGroup)
	})
}
Exemplo n.º 14
0
func InitUsersRoutes(r martini.Router) {
	r.Group("/admin/users", func(router martini.Router) {
		router.Get("/get/:id", getUser)
		router.Get("/list", getUsers)
		router.Get("/get/:id/roles/application/:appId", getUserRoles)
		router.Post("/create", createUsers)
		router.Post("/update", updateUsers)
		router.Post("/delete/:id", deleteUser)
	})
}
Exemplo n.º 15
0
func attachAPI(api martini.Router) {
	api.Get("/user", getCurrentUser)
	api.Get("/users", getUsers)
	api.Post("/users", newUser)

	api.Get("/users/:name", getUser)
	//api.Put("/users/:name", updateUser)

	api.Get("/users/:name/projects", getProjects)
	//api.Post("/users/:name/projects", newProject)

	//apiGets.HandleFunc("/projects", getProjects)
}
Exemplo n.º 16
0
func EnsureAuth(r martini.Router, mainDb *d.MainDb) martini.Router {

	r.Get("/", func(r render.Render, prms martini.Params, req *http.Request) {
		flashMessage, fType := flash.GetMessage()
		query := req.URL.Query()
		result := map[string]interface{}{
			fmt.Sprintf("flash_%v", fType): flashMessage,
			"from": query.Get("from"),
		}

		r.HTML(200, "login", AddCurrentUser(result, req, mainDb), render.HTMLOptions{Layout: "base"})
	})

	r.Post("/", binding.Bind(user{}), func(postedUser user, r render.Render, req *http.Request, w http.ResponseWriter) {
		userData, err := mainDb.Users.LoginUser(postedUser.LoginName, postedUser.Password)
		if err != nil {
			log.Printf("AUTH user %+v not found: %v", postedUser, err)
			flash.SetMessage("К сожалению, пользователь с такими данными не найден.", "error")
			r.Redirect(AUTH_URL)
			return
		} else {
			log.Printf("AUTH found user data: %v, %v, %v", userData.UserId, userData.UserName, userData.Auth)
		}
		user := NewUser(userData)
		StartAuthSession(user, w)
		redirect := req.URL.Query().Get(REDIRECT_PARAM)
		if redirect == "" {
			redirect = DefaultUrlMap.GetDefaultUrl(user.BelongsToCompany())
		}
		http.Redirect(w, req, redirect, 302)
	})
	return r
}
Exemplo n.º 17
0
func (lr *SiteRouter) Register(r martini.Router) {

	r.Get("", lr.GetAll)
	r.Get("/:id", lr.GetSite)
	r.Put("/:id", lr.PutSite)
	r.Delete("/:id", lr.DeleteSite)

}
Exemplo n.º 18
0
// AdminRoute manages routing for Restful API
func AdminRoute(r martini.Router) {
	r.Get("/rest/metadata", AdminGetModels)
	r.Get("/rest/metadata/:modelName", AdminGetMetaData)
	r.Group("/rest/:modelName", func(restRoutes martini.Router) {
		restRoutes.Get("", AdminGetList)
		restRoutes.Get("/:id", AdminGetEntity)
		restRoutes.Post("", AdminNewEntity)
		restRoutes.Put("/:id", AdminUpdateEntity)
		restRoutes.Delete("/:id", AdminDeleteEntity)
	})
	r.Get("/", AdminIndex)
}
Exemplo n.º 19
0
func (lr *LocationRouter) Register(r martini.Router) {

	r.Get("/calibration/scores", lr.GetCalibrateScores)
	r.Get("/calibration/device", lr.GetCalibrateDevice)
	r.Get("/calibration/progress", lr.GetCalibrationProgress)

	r.Post("/thing", lr.PostCreateThing)

}
Exemplo n.º 20
0
func addNeedRoutes(r martini.Router) {
	r.Group("/needs", func(r martini.Router) {
		r.Get("", func() string {
			return "All my needs"
		})
		r.Get("/:id", func(p martini.Params) string {
			return "Need(" + p["id"] + ")"
		})
	})
}
Exemplo n.º 21
0
func (this *EurekaRequestPut) SetRoutes(r martini.Router) {
	r.Put("/apps/:appId/:instanceId", this.requestHeartBeat)
}
Exemplo n.º 22
0
func (ps ProjectService) Register(router martini.Router) {
	router.Group("/projects", func(rtr martini.Router) {
		rtr.Get("/new", ps.New)
		rtr.Post("", binding.Bind(models.Project{}), ps.Create)
	}, EnsureAuth)
}
Exemplo n.º 23
0
func SetupCommentRoutes(r martini.Router) {
	r.Get("/comments", ListComments)
	r.Get("/todo/:id/comments", ListCommentsByTodo)
	r.Post("/comments", binding.Json(Comment{}), CreateComment)
}
Exemplo n.º 24
0
func initBooksApi(r martini.Router) {
	r.Group("/books", func(r martini.Router) {
		r.Get("", getBooks)
	})
}
Exemplo n.º 25
0
func RegisterRoutes(r martini.Router) {
	r.Get("/debug/pprof/cmdline", pprof.Cmdline)
	r.Get("/debug/pprof/profile", pprof.Profile)
	r.Get("/debug/pprof/symbol", pprof.Symbol)
	r.Get("/debug/pprof/**", pprof.Index)
}
Exemplo n.º 26
0
func userRouter(r martini.Router) {
	r.Get("/one", one)
	r.Get("/two", two)
}
Exemplo n.º 27
0
func (this *EurekaRequestGet) SetRoutes(r martini.Router) {
	r.Get("/apps", this.requestApplications)
	r.Get("/apps/:appId", this.requestApplication)
	r.Get("/apps/:appId/:instanceId", this.requestInstance)
}
Exemplo n.º 28
0
func configureRoutes(router martini.Router) {
	// 404 handler
	router.NotFound(func(render render.Render) {
		render.Redirect("/404")
	})

	// Common Routes
	router.Get("/", controllers.Home)
	router.Get("/404", controllers.NotFound)
	router.Get("/500", controllers.InternalServerError)

	// Player Routes
	router.Get("/players", controllers.GetPlayers)
	router.Get("/player/new", controllers.GetNewPlayer)
	router.Post("/player/new", binding.Form(controllers.PlayerData{}), controllers.CreatePlayer)
	router.Get("/player/:id", controllers.GetPlayerById)
	router.Post("/player/:id", binding.Form(controllers.PlayerData{}), binding.Form(controllers.OriginalData{}), controllers.ModifyPlayer)

	// Game Routes
	router.Get("/games", controllers.GetGames)
	router.Get("/game/new", controllers.GetNewGame)
	router.Post("/game/new", binding.Form(controllers.GameData{}), controllers.CreateGame)
	router.Get("/game/:id", controllers.GetGameById)
}
Exemplo n.º 29
0
func (ws WebhookService) Register(router martini.Router) {
	router.Post("/webhook/:git_service", ws.Handle)
}
Exemplo n.º 30
0
func (this *EurekaRequestDelete) SetRoutes(r martini.Router) {
	r.Delete("/apps/:appId/:instanceId", this.requestUnregisterInstance)
}