• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang wcg.Router类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/speedland/wcg.Router的典型用法代码示例。如果您正苦于以下问题:Golang Router类的具体用法?Golang Router怎么用?Golang Router使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Router类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: configurePosts

func configurePosts(routes *wcg.Router) {
	routes.Get("/:blog_id/:post_id/", showPostHandler)
	routes.Post("/admin/blogs/:blog_id/", createPostHandler)
	routes.Get("/admin/blogs/:blog_id/:post_id/", editPostHandler)
	routes.Put("/admin/blogs/:blog_id/:post_id/", updatePostHandler)
	routes.Delete("/admin/blogs/:blog_id/:post_id/", deletePostHandler)
}
开发者ID:speedland,项目名称:rakugaki,代码行数:7,代码来源:posts.go


示例2: registerResponseHelperHandlers

func registerResponseHelperHandlers(routes *wcg.Router) {
	routes.Before(func(res *wcg.Response, req *wcg.Request) {
		var app *App
		tmp := strings.Split(req.URL().Path, "/")
		req.Logger.Info("App is :%s", tmp[1])
		switch tmp[1] {
		case "api", "cron":
			app = apps[tmp[2]]
			break
		default:
			app = apps[tmp[1]]
		}
		if app == nil {
			req.Logger.Debug("No app is identified.")
			return
		}
		// request locals
		req.SetLocal(LOCAL_APP_KEY, app)
		res.SetLocal(LOCAL_APP_KEY, app)
		// response locals
		uk := GetUserKind(req)
		navs := make([]*Page, 0)
		for _, nav := range app.navigations {
			req.Logger.Debug("Checking %s nav availablity: (%d, %d)", nav.Title, uk, nav.authority)
			if uk >= nav.authority {
				navs = append(navs, nav)
			}
		}
		res.SetLocal(LOCAL_NAVIGATIONS_KEY, navs)
	})
}
开发者ID:speedland,项目名称:apps,代码行数:31,代码来源:response_helper.go


示例3: RouteTo

func (t *TestRequest) RouteTo(r *wcg.Router) *TestResponse {
	r.Dispatch(t.res, t.Request)
	body, err := ioutil.ReadAll(t.recorder.Body)
	if err != nil {
		panic(err)
	}
	return &TestResponse{
		t.recorder.Code,
		t.recorder.Header(),
		body,
		t,
	}
}
开发者ID:speedland,项目名称:wcg,代码行数:13,代码来源:httptest.go


示例4: registerJsonpProxyHandlers

func registerJsonpProxyHandlers(routes *wcg.Router) {
	routes.Get("/jsonp", func(res *wcg.Response, req *wcg.Request) {
		target := req.Query("_jsonpurl")
		if target == "" {
			res.WriteJsonWithStatus(400, nil, map[string]interface{}{
				"error": "_jsonpurl must be specified.",
			})
			return
		}
		if _url, err := url.Parse(target); err != nil {
			res.WriteJsonWithStatus(400, nil, map[string]interface{}{
				"error": "_jsonpurl cannot be parsed.",
			})
			return
		} else {
			if _url.Scheme != "http" && _url.Scheme != "https" {
				res.WriteJsonWithStatus(400, nil, map[string]interface{}{
					"error": "non http(s) scheme is allowed.",
				})
				return
			}
			if _, ok := JsonpProxyWhiteList[_url.Host]; !ok {
				res.WriteJsonWithStatus(400, nil, map[string]interface{}{
					"error": fmt.Sprintf("%s is not allowed to proxy.", _url.Host),
				})
				return
			}
		}
		query := req.HttpRequest().URL.Query()
		query.Del("_jsonpurl")
		client := gae.NewHttpClient(req)
		resp, err := client.Get(fmt.Sprintf("%s?%s", target, query.Encode()))
		if resp == nil {
			Error(res, req, err)
			return
		}
		defer resp.Body.Close()
		res.WriteHeader(resp.StatusCode)
		io.Copy(res, resp.Body)
	})
}
开发者ID:speedland,项目名称:apps,代码行数:41,代码来源:jsonp_proxy.go


示例5: registerCronHandlers

func registerCronHandlers(routes *wcg.Router) {
	routes.Get("/cron.yaml", func(res *wcg.Response, req *wcg.Request) {
		res.Header().Add("Content-Type", "text/yaml")
		res.WriteString("cron:\n")
		applist := make([]string, 0)
		for _, app := range apps {
			if len(app.Cron.entries) > 0 {
				applist = append(applist, app.Key)
			}
		}
		applist = sort.StringSlice(applist)
		for _, appName := range applist {
			app := apps[appName]
			res.WriteString("# Application -- %s\n", app.Key)
			for _, ent := range app.Cron.entries {
				res.WriteString("- url:         %s\n", ent.Url)
				res.WriteString("  schedule:    %s\n", ent.Schedule)
				res.WriteString("  description: %s\n", ent.Description)
				res.WriteString("  timezone:    %s\n\n", "Asia/Tokyo")
			}
		}
	})
}
开发者ID:speedland,项目名称:apps,代码行数:23,代码来源:cron.go


示例6: registerAhHandlers

func registerAhHandlers(routes *wcg.Router) {
	routes.Get("/_ah/start", func(res *wcg.Response, req *wcg.Request) {
		for _, app := range apps {
			if app.Start != nil {
				req.Logger.Info("%q start handler", app.Key)
				req.SetLocal(LOCAL_APP_KEY, app)
				res.SetLocal(LOCAL_APP_KEY, app)
				app.Start(res, req)
			}
		}
		res.WriteString("OK")
	})
	routes.Get("/_ah/warmup", func(res *wcg.Response, req *wcg.Request) {
		for _, app := range apps {
			if app.Warmup != nil {
				req.Logger.Info("%q warmup handler", app.Key)
				req.SetLocal(LOCAL_APP_KEY, app)
				res.SetLocal(LOCAL_APP_KEY, app)
				app.Warmup(res, req)
			}
		}
		res.WriteString("OK")
	})
}
开发者ID:speedland,项目名称:apps,代码行数:24,代码来源:ah.go


示例7: registerAuthHandlers

func registerAuthHandlers(routes *wcg.Router) {
	middleware.SessionConfigIni.StoreFactory = gae.GAESessionStoreFactory
	sessionBefore, sessionAfter := middleware.SessionSupport()
	fbconfig := facebookConfig()
	fbauth, fbcallback, fbvalidates, fblogout := middleware.OAuth2(fbconfig)
	csrf := middleware.CSRFSupport()

	// resolve the access user
	routes.Before(func(res *wcg.Response, req *wcg.Request) {
		if apiTokenAuthHandler(res, req) {
			req.Logger.Debug("Api Token Auth: Yes")
			req.SetLocal(LOCAL_KEY_AUTH_TYPE, AUTH_TYPE_API_TOKEN)
			return
		}
		req.Logger.Debug("Api Token Auth: No")
		if cronAuthHandler(res, req) {
			req.Logger.Debug("Cron Auth: Yes")
			req.SetLocal(LOCAL_KEY_AUTH_TYPE, AUTH_TYPE_CRON)
			return
		}
		req.Logger.Debug("Cron Auth: No")

		if ahAuthHandler(res, req) {
			req.Logger.Debug("Ah Auth: Yes")
			req.SetLocal(LOCAL_KEY_AUTH_TYPE, AUTH_TYPE_AH)
			return
		}
		req.Logger.Debug("Ah Auth: No")
		req.Logger.Debug("Session Auth: Yes")

		sessionBefore(res, req)
		res.SetLocal(LOCAL_KEY_AUTH_TYPE, AUTH_TYPE_COOKIE)
		fbvalidates(res, req)

		res.SetLocal("fb_app_id", fbconfig.ClientId)
		res.SetLocal("wcg_user", util.FormatJson(map[string]interface{}{
			"id":           req.User.Id(),
			"display_name": req.User.DisplayName(),
			"image_link":   req.User.ImageLink(),
			"profile_link": req.User.ProfileLink(),
			"last_login":   req.User.LastLogin(),
			"user_kind":    GetUserKind(req),
		}))

		if req.Method() != "GET" && req.Method() != "HEAD" {
			csrf(res, req)
		}
	})

	// AUthorization Endpoint
	routes.Get("/login/facebook", func(res *wcg.Response, req *wcg.Request) {
		if req.Query("ref") != "" {
			req.Session.Set(SESSION_KEY_LOGIN_REF, req.Query("ref"))
		}
		fbauth(res, req)
	})
	routes.Get("/login/facebook/callback", fbcallback)
	routes.Post("/logout/facebook", func(res *wcg.Response, req *wcg.Request) {
		fblogout(res, req)
		res.Redirect("/", http.StatusFound)
	})

	// Save the session data
	routes.After(func(res *wcg.Response, req *wcg.Request) {
		if auth_type, ok := res.Local(LOCAL_KEY_AUTH_TYPE).(string); ok && auth_type == AUTH_TYPE_COOKIE {
			sessionAfter(res, req)
		}
	})
}
开发者ID:speedland,项目名称:apps,代码行数:69,代码来源:auth.go


示例8: configureBlogs

func configureBlogs(routes *wcg.Router) {
	// check user is already signed in or not.
	routes.All("/admin/blogs/*", func(res *wcg.Response, req *wcg.Request) {
		if wcg.IsGuest(req.User) {
			res.Redirect("/", http.StatusFound)
		}
	})
	// public interfaces.
	routes.Get("/my/", myblogRedirector(true))
	routes.Get("/:blog_id/", showBlogHandler)
	// admin interfaces
	routes.Get("/admin/blogs/my/", myblogRedirector(false))
	routes.Get("/admin/blogs/:blog_id/", manageBlogHandler)
	routes.Post("/admin/blogs/", createBlogHandler)
	routes.Put("/admin/blogs/:blog_id/", updateBlogHandler)
	routes.Delete("/admin/blogs/:blog_id/", deleteBlogHandler)
}
开发者ID:speedland,项目名称:rakugaki,代码行数:17,代码来源:blogs.go


示例9: configureOAuth

func configureOAuth(routes *wcg.Router) {
	GoogleAuthConfig, _ := google.NewAuthConfigFromFile("")
	FacebookAuthConfig, _ := facebook.NewAuthConfigFromFile("")
	GoogleAuthConfig.RedirectURL = "/login/google/callback"
	GoogleAuthConfig.TransportFactory = gae.NewHttpTransport
	GoogleAuthConfig.UnauthorizedHandler = unauthorized
	GoogleAuthConfig.AuthorizedHandler = authorized
	GoogleAuthConfig.InvalidatedHandler = invalidated
	gauth, gcallback, gvalidates, glogout := middleware.OAuth2(GoogleAuthConfig)
	routes.All("/*", gvalidates)
	routes.Get("/login/google", gauth)
	routes.Get("/login/google/callback", gcallback)
	routes.Get("/logout/google", glogout)

	FacebookAuthConfig.RedirectURL = "/login/facebook/callback"
	FacebookAuthConfig.TransportFactory = gae.NewHttpTransport
	FacebookAuthConfig.UnauthorizedHandler = unauthorized
	FacebookAuthConfig.AuthorizedHandler = authorized
	FacebookAuthConfig.InvalidatedHandler = invalidated
	fbauth, fbcallback, fbvalidates, fblogout := middleware.OAuth2(FacebookAuthConfig)
	routes.All("/*", fbvalidates)
	routes.All("/*", func(res *wcg.Response, req *wcg.Request) {
		res.SetLocal("fb_app_id", FacebookAuthConfig.ClientId)
	})
	routes.Get("/login/facebook", fbauth)
	routes.Get("/login/facebook/callback", fbcallback)
	routes.Post("/logout/facebook", fblogout)
}
开发者ID:speedland,项目名称:rakugaki,代码行数:28,代码来源:oauth.go



注:本文中的github.com/speedland/wcg.Router类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang test.NewAssert函数代码示例发布时间:2022-05-28
下一篇:
Golang wcg.Response类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap