本文整理匯總了Golang中github.com/go-martini/martini.ClassicMartini類的典型用法代碼示例。如果您正苦於以下問題:Golang ClassicMartini類的具體用法?Golang ClassicMartini怎麽用?Golang ClassicMartini使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了ClassicMartini類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: FakeKeystone
//FakeKeystone server for only test purpose
func FakeKeystone(martini *martini.ClassicMartini) {
//mocking keystone v2.0 API
martini.Post("/v2.0/tokens", func(w http.ResponseWriter, r *http.Request) {
authRequest, err := ReadJSON(r)
if err != nil {
http.Error(w, "", http.StatusBadRequest)
}
username, err := util.GetByJSONPointer(authRequest, "/auth/passwordCredentials/username")
if err != nil {
http.Error(w, "", http.StatusBadRequest)
}
token, ok := fakeTokens[fmt.Sprintf("%v_token", username)]
if !ok {
http.Error(w, "", http.StatusUnauthorized)
}
serializedToken, _ := json.Marshal(token)
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Content-Length", strconv.Itoa(len(serializedToken)))
w.Write(serializedToken)
})
for tokenID, rawToken := range fakeTokens {
serializedToken, _ := json.Marshal(rawToken)
martini.Get("/v2.0/tokens/"+tokenID, func(w http.ResponseWriter, r *http.Request) {
w.Write(serializedToken)
})
}
}
示例2: Routes
func (routeUserDelete *RouteUserDelete) Routes(m *martini.ClassicMartini) {
m.Post("/user/delete", func(w http.ResponseWriter, r *http.Request) string {
log.WriteLog("addr: /user/delete")
SetResponseJsonHeader(w)
setupInfo := model.SetupInfo{}
setupHandle := model.NewSetupHandle()
if !setupHandle.GetSetupInfo(&setupInfo) {
return model.GetErrorDtoJson("讀取用戶信息失敗")
}
r.ParseForm()
log.WriteLog("user delete %v", r.Form)
userName := r.Form.Get("username")
if common.USER_NAME_ADMIN == userName {
log.WriteLog("刪除admin失敗")
return model.GetErrorDtoJson("刪除管理員信息失敗")
}
if !setupInfo.DeleteUserByUserName(userName) {
log.WriteLog("刪除用戶信息失敗")
return model.GetErrorDtoJson("刪除用戶信息失敗")
}
if !setupHandle.SaveSetupInfo(&setupInfo) {
log.WriteLog("保存刪除用戶信息失敗")
return model.GetErrorDtoJson("保存刪除用戶信息失敗")
}
return model.GetDataDtoJson(nil)
})
}
示例3: Routes
func (routeServerGeneralInfo *RouteServerGeneralInfo) Routes(m *martini.ClassicMartini) {
m.Get("/server/info/general", func(w http.ResponseWriter, r *http.Request) string {
log.WriteLog("addr: /server/info/general")
shttp.SetResponseJsonHeader(w)
result := map[string]string{}
val, err := service.NewGetSystemTimeInfo().GetInfo()
if nil != err {
return model.GetErrorObjDtoJson(err)
}
result["time"] = val
runTimeInfo, err1 := service.NewGetSystemRunTimeInfo().GetInfo()
if nil != err1 {
return model.GetErrorObjDtoJson(err1)
}
result["runtime"] = fmt.Sprintf("%d天 %d小時 %d分鍾", runTimeInfo.Day, runTimeInfo.Hour, runTimeInfo.Min)
hostname, err3 := os.Hostname()
if nil != err3 {
return model.GetErrorObjDtoJson(err3)
}
result["hostname"] = hostname
ver, err2 := utils.CmdOutputNoLn("uname", "-r")
if nil != err2 {
return model.GetErrorObjDtoJson(err2)
}
result["kernel"] = ver
return model.GetDataDtoJson(result)
})
}
示例4: AddWs
func AddWs(m *martini.ClassicMartini, c *container.ContainerBag) {
clientList = newClientList()
go monitorBuilders(c)
m.Get("/ws", sockets.JSON(Message{}),
func(params martini.Params,
receiver <-chan *Message,
sender chan<- *Message,
done <-chan bool,
disconnect chan<- int,
err <-chan error) (int, string) {
client := &Client{receiver, sender, done, err, disconnect}
clientList.appendClient(client)
for {
select {
case <-client.done:
clientList.removeClient(client)
return 200, "OK"
}
}
})
}
示例5: testResponses
func testResponses(t *testing.T, m *martini.ClassicMartini, expectations ...*Expectation) {
for _, expectation := range expectations {
req, err := http.NewRequest("GET", "/test", strings.NewReader(""))
reflect.ValueOf(req).Elem().FieldByName("RemoteAddr").SetString("1.2.3.4:5000")
if err != nil {
t.Error(err)
}
time.Sleep(expectation.Wait)
recorder := httptest.NewRecorder()
m.ServeHTTP(recorder, req)
expectStatusCode(t, expectation.StatusCode, recorder.Code)
if expectation.Body != "" {
expectSame(t, recorder.Body.String(), expectation.Body)
}
expectSame(t, recorder.Header()["X-Ratelimit-Limit"][0], expectation.RateLimitLimit)
expectSame(t, recorder.Header()["X-Ratelimit-Remaining"][0], expectation.RateLimitRemaining)
resetTime, err := strconv.ParseInt(recorder.Header()["X-Ratelimit-Reset"][0], 10, 64)
if err != nil {
t.Errorf(err.Error())
}
expectApproximateTimestamp(t, resetTime, expectation.RateLimitReset)
}
}
示例6: setupMiddleware
func (srv *httpServer) setupMiddleware(m *martini.ClassicMartini) {
m.Use(render.Renderer(render.Options{
Directory: "templates",
Layout: "layout",
}))
m.Use(CORSAllowAny())
}
示例7: mapRoutes
func mapRoutes(m *martini.ClassicMartini) {
m.Post("/githook", handleGitHook)
m.Get("/auth", authGitHub)
m.Get("/githubAuth", gitHubAuthMiddleware, getUserFromToken)
m.Get("/award", gandalf, awardUser)
m.Post("/submission", gandalf, csrf.Validate, handleSubmission)
}
示例8: controller
//controller轉發規則設置
func controller(m *martini.ClassicMartini) { // {{{
m.Get("/", func(r render.Render) {
r.HTML(200, "index", nil)
})
m.Group("/schedules", func(r martini.Router) {
//Schedule部分
r.Get("", GetSchedules)
r.Post("", binding.Bind(schedule.Schedule{}), AddSchedule)
r.Get("/:id", GetScheduleById)
r.Put("/:id", binding.Bind(schedule.Schedule{}), UpdateSchedule)
r.Delete("/:id", DeleteSchedule)
//Job部分
r.Get("/:sid/jobs", GetJobsForSchedule)
r.Post("/:sid/jobs", binding.Bind(schedule.Job{}), AddJob)
r.Put("/:sid/jobs/:id", binding.Bind(schedule.Job{}), UpdateJob)
r.Delete("/:sid/jobs/:id", DeleteJob)
//Task部分
r.Post("/:sid/jobs/:jid/tasks", binding.Bind(schedule.Task{}), AddTask)
r.Put("/:sid/jobs/:jid/tasks/:id", binding.Bind(schedule.Task{}), UpdateTask)
r.Delete("/:sid/jobs/:jid/tasks/:id", DeleteTask)
//TaskRelation部分
r.Post("/:sid/jobs/:jid/tasks/:id/reltask/:relid", AddRelTask)
r.Delete("/:sid/jobs/:jid/tasks/:id/reltask/:relid", DeleteRelTask)
})
} // }}}
示例9: SetupRoutes
func SetupRoutes(m *martini.ClassicMartini) {
m.Get("/", Leaderboard)
m.Get("/leaders", GetLeaders)
m.Get("/leaders/:page", GetLeaders)
m.Get("/leader/:name", GetLeader)
m.Post("/leader", binding.Json(Leader{}), binding.ErrorHandler, PostLeader)
}
示例10: InitSession
//InitSession - initializes authentication middleware for controllers
func InitSession(m *martini.ClassicMartini, rc redisCreds) {
m.Use(render.Renderer())
if rediStore, err := sessions.NewRediStore(10, "tcp", rc.Uri(), rc.Pass(), []byte(sessionSecret)); err == nil {
m.Use(sessions.Sessions(sessionName, rediStore))
}
}
示例11: RouterSiginInit
func RouterSiginInit(m *martini.ClassicMartini) {
m.Group("/sign", func(r martini.Router) {
r.Get("/in", SignIn)
r.Post("/in/todo", SignInTodo)
r.Get("/up", SignUp)
r.Post("/up/todo", SignUpTodo)
})
}
示例12: RegisterRequests
// RegisterRequests makes for the de-facto list of known API calls
func (this *HttpAgentsAPI) RegisterRequests(m *martini.ClassicMartini) {
m.Get("/api/submit-agent/:host/:port/:token", this.SubmitAgent)
m.Get("/api/host-attribute/:host/:attrVame/:attrValue", this.SetHostAttribute)
m.Get("/api/host-attribute/attr/:attr/", this.GetHostAttributeByAttributeName)
m.Get("/api/agents-hosts", this.AgentsHosts)
m.Get("/api/agents-instances", this.AgentsInstances)
m.Get("/api/agent-ping", this.AgentPing)
}
示例13: InitDebugMiddleware
func InitDebugMiddleware(m *martini.ClassicMartini) {
m.Use(PARAMS)
m.Use(DB())
m.Use(sessions.Sessions("lol_session", sessions.NewCookieStore([]byte("secret123"))))
m.Use(render.Renderer(render.Options{Directory: TemplatesLocation}))
m.Use(martini.Static("resources/public", martini.StaticOptions{Prefix: "/public"}))
SetId("1", "10153410152015744", "Sean Myers") // Me. Set these to act like facebook, using a nice cache
}
示例14: RouterUserInit
func RouterUserInit(m *martini.ClassicMartini) {
m.Group("/user", func(r martini.Router) {
r.Get("/list", ListUser)
r.Get("/upd/:id", UpdUser)
r.Post("/upd/todo", UpdUserTodo)
r.Get("/del/:id", DelUser)
}, middlewares.Auth())
}
示例15: route
// martini router
func route(m *martini.ClassicMartini) {
// regist a device
m.Post("/v1/devices/registration", binding.Json(DeviceRegisterArgs{}), RegisterDevice)
// auth device
// m.Post("v1/devices/authentication", binding.Json(DeviceAuthArgs{}), actions.AuthDevice)
}