當前位置: 首頁>>代碼示例>>Golang>>正文


Golang martini.ClassicMartini類代碼示例

本文整理匯總了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)
		})
	}
}
開發者ID:marcin-ptaszynski,項目名稱:gohan,代碼行數:31,代碼來源:fake.go

示例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)
	})
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:29,代碼來源:routeUserDelete.go

示例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)
	})
}
開發者ID:johnnywww,項目名稱:swd,代碼行數:28,代碼來源:routeServerGeneralInfo.go

示例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"
				}
			}
		})
}
開發者ID:nbari,項目名稱:buildbot-dashboard,代碼行數:25,代碼來源:ws.go

示例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)
	}
}
開發者ID:hongzhen,項目名稱:throttle,代碼行數:25,代碼來源:throttle_test.go

示例6: setupMiddleware

func (srv *httpServer) setupMiddleware(m *martini.ClassicMartini) {
	m.Use(render.Renderer(render.Options{
		Directory: "templates",
		Layout:    "layout",
	}))
	m.Use(CORSAllowAny())
}
開發者ID:joshk,項目名稱:hustle,代碼行數:7,代碼來源:http_server.go

示例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)
}
開發者ID:nquinlan,項目名稱:contribot,代碼行數:7,代碼來源:utils.go

示例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)
	})

} // }}}
開發者ID:rprp,項目名稱:hivego,代碼行數:31,代碼來源:manager.go

示例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)
}
開發者ID:nghiangodinh,項目名稱:sample-go-webapp,代碼行數:7,代碼來源:routes.go

示例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))
	}
}
開發者ID:malston,項目名稱:pezauth,代碼行數:8,代碼來源:auth.go

示例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)
	})
}
開發者ID:Zxnui,項目名稱:go-martini-test,代碼行數:8,代碼來源:controller_sign.go

示例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)
}
開發者ID:0-T-0,項目名稱:orchestrator,代碼行數:9,代碼來源:agents_api.go

示例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
}
開發者ID:lab-D8,項目名稱:lol-at-pitt,代碼行數:8,代碼來源:middleware.go

示例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())
}
開發者ID:Zxnui,項目名稱:go-martini-test,代碼行數:8,代碼來源:controller_user.go

示例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)

}
開發者ID:oskycar,項目名稱:pando-cloud,代碼行數:9,代碼來源:router.go


注:本文中的github.com/go-martini/martini.ClassicMartini類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。