本文整理匯總了Golang中github.com/go-martini/martini.Router類的典型用法代碼示例。如果您正苦於以下問題:Golang Router類的具體用法?Golang Router怎麽用?Golang Router使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Router類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: AddRoutes
func AddRoutes(r martini.Router) {
r.Group("/api/v1", func(r martini.Router) {
addNeedRoutes(r)
addResourceRoutes(r)
addStaffRoutes(r)
}, MapCodec)
}
示例2: mapChildNamespaceRoute
// 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})
},
)
}
示例3: addStaffRoutes
func addStaffRoutes(r martini.Router) {
r.Group("/staff", func(r martini.Router) {
r.Get("", func() string {
return "Staff stuff?"
})
}, ensureStaffMember)
}
示例4: Register
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)
}
示例5: mapTopLevelNamespaceRoute
// 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})
})
}
示例6: CreateJobsRoutes
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)
}
示例7: setup
func setup(router martini.Router) {
router.Get("/user/:id", controllers.UserGet)
router.Put("/user/:id",
binding.Json(models.User{}),
binding.ErrorHandler,
controllers.UserPut)
}
示例8: initCurrencyApi
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
})
})
}
示例9: InitApplicationsRoutes
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)
})
}
示例10: Register
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)
}
示例11: addResourceRoutes
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"] + ")"
})
}
示例12: InitRolesRoutes
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)
})
}
示例13: InitGroupsRoutes
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)
})
}
示例14: InitUsersRoutes
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)
})
}
示例15: attachAPI
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)
}