本文整理汇总了Golang中goji/io/pat.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
stderrBackend := logging.NewLogBackend(os.Stderr, "", 0)
stderrFormatter := logging.NewBackendFormatter(stderrBackend, stdout_log_format)
logging.SetBackend(stderrFormatter)
logging.SetFormatter(stdout_log_format)
log.Info("Starting app")
log.Debugf("version: %s", version)
if !strings.ContainsRune(version, '-') {
log.Warning("once you tag your commit with name your version number will be prettier")
}
log.Error("now add some code!")
renderer, err := web.New()
if err != nil {
log.Errorf("Renderer failed with: %s", err)
}
mux := goji.NewMux()
mux.Handle(pat.Get("/static/*"), http.StripPrefix("/static", http.FileServer(http.Dir(`public/static`))))
mux.Handle(pat.Get("/apidoc/*"), http.StripPrefix("/apidoc", http.FileServer(http.Dir(`public/apidoc`))))
mux.HandleFunc(pat.Get("/"), renderer.HandleRoot)
mux.HandleFunc(pat.Get("/status"), renderer.HandleStatus)
log.Warningf("listening on %s", listenAddr)
log.Errorf("failed on %s", http.ListenAndServe(listenAddr, mux))
}
示例2: TestInvalidStates
// test really long resource paths (limit to what securecookie can encode)
func TestInvalidStates(t *testing.T) {
// resource path
respath := "/" + strings.Repeat("x", 4096)
// setup oauthmw
sess := newSession()
prov := newProvider()
prov.Path = "/"
prov.Configs = map[string]*oauth2.Config{
"google": newGoogleEndpoint(""),
}
// setup mux and middleware
m0 := goji.NewMux()
m0.UseC(sess.Handler)
m0.UseC(prov.RequireLogin(nil))
m0.HandleFuncC(pat.Get("/*"), okHandler)
r0, _ := get(m0, respath, nil, t)
checkError(500, "could not encode state for google", r0, t)
//--------------------------------------
// repeat above test, but with multiple providers
prov.Configs["facebook"] = newFacebookEndpoint("")
// setup mux and middleware
m1 := goji.NewMux()
m1.UseC(sess.Handler)
m1.UseC(prov.RequireLogin(nil))
m1.HandleFuncC(pat.Get("/*"), okHandler)
r1, _ := get(m1, respath, nil, t)
checkError(500, "could not encode state for facebook (2)", r1, t)
}
示例3: main
func main() {
mux := goji.NewMux()
mux.HandleFuncC(pat.Get("/hello/:name"), hello)
mux.HandleFuncC(pat.Get("/goodbye/:name"), goodbye)
http.ListenAndServe(":8000", mux)
}
示例4: main
func main() {
mux := goji.NewMux()
mux.HandleFuncC(pat.Get("/books"), allBooks)
mux.HandleFuncC(pat.Get("/books/:isbn"), bookByISBN)
mux.UseC(logging)
http.ListenAndServe("localhost:8080", mux)
}
示例5: main
func main() {
router := goji.NewMux()
router.HandleFunc(pat.Get("/"), index)
router.HandleFuncC(pat.Get("/hello/:name"), hello)
log.Println("Starting server on port 9090")
log.Fatal(http.ListenAndServe(":9090", router))
}
示例6: Web
func Web() *goji.Mux {
mux := goji.SubMux()
mux.HandleFuncC(pat.Get("/people"), frontend.ListPeople)
mux.HandleFuncC(pat.Get("/people/:person"), frontend.GetPerson)
return mux
}
示例7: Listen
func Listen() {
mux := goji.NewMux()
mux.HandleFunc(pat.Post("/reset.json"), reset)
mux.HandleFuncC(pat.Get("/:name.json"), show)
mux.HandleFunc(pat.Get("/"), index)
bind := fmt.Sprintf(":%s", getBindPort())
log.Fatal(http.ListenAndServe(bind, mux))
}
示例8: init
func init() {
mux := goji.NewMux()
mux.HandleFuncC(pat.Get("/"), index)
mux.HandleFuncC(pat.Get("/hello/:name"), hello)
mux.HandleFuncC(pat.Get("/article"), article)
http.Handle("/", mux)
}
示例9: TestRequireLoginAutoRedirect
func TestRequireLoginAutoRedirect(t *testing.T) {
// setup mux's
m0 := goji.NewMux()
m1 := goji.NewMux()
m1Sub := goji.NewMux()
m1.HandleC(pat.Get("/p/*"), m1Sub)
m2 := goji.NewMux()
m2Sub := goji.NewMux()
m2.HandleC(pat.Get("/p/*"), m2Sub)
tests := []struct {
mux *goji.Mux
addToMux *goji.Mux
path string
redir string
}{
{m0, m0, "/", "/oauth-redirect-google?state="},
{m1, m1, "/", "/oauth-redirect-google?state="},
/*{m1, m1Sub, "/p/", "/p/oauth-redirect-google?state="},
{m2, m2, "/p/", "/p/oauth-redirect-google?state="},
{m2, m2Sub, "/p/", "/p/oauth-redirect-google?state="},*/
}
for i, test := range tests {
// setup middleware
sess := newSession()
prov := newProvider()
prov.Path = test.path
prov.Configs = map[string]*oauth2.Config{
"google": newGoogleEndpoint(""),
}
// enable subrouter test for m2Sub
/*if test.addToMux == m2Sub {
prov.SubRouter = true
}*/
// add middleware to mux
sessmw := sess.Handler
rlmw := prov.RequireLogin(nil)
test.addToMux.UseC(sessmw)
test.addToMux.UseC(rlmw)
// check for redirect
r0, l0 := get(test.mux, test.path, nil, t)
check(302, r0, t)
if !strings.HasPrefix(l0, test.redir) {
t.Errorf("test %d invalid redirect %s", i, l0)
}
// remove middleware from mux so they can be reused
//test.addToMux.Abandon(rlmw)
//test.addToMux.Abandon(sessmw)
}
}
示例10: Listen
func Listen() {
mux := goji.NewMux()
mux.HandleFuncC(pat.Get("/:name.json"), show)
mux.HandleFunc(pat.Get("/"), index)
bind := ":"
if port := os.Getenv("PORT"); port != "" {
bind += port
} else {
bind += "8000"
}
log.Fatal(http.ListenAndServe(bind, mux))
}
示例11: TestLogin
func TestLogin(t *testing.T) {
// setup oauthmw
sess := newSession()
prov := newProvider()
prov.Path = "/"
prov.Configs = map[string]*oauth2.Config{
"google": newGoogleEndpoint(""),
"facebook": newFacebookEndpoint(""),
}
prov.checkDefaults()
// setup mux and middleware
m0 := goji.NewMux()
m0.UseC(sess.Handler)
m0.UseC(prov.Login(nil))
m0.HandleFuncC(pat.Get("/ok"), okHandler)
// do initial request to establish session
r0, _ := get(m0, "/ok", nil, t)
checkOK(r0, t)
cookie := getCookie(r0, t)
// verify 404 if no/bad state provided
r1, _ := get(m0, "/oauth-redirect-google", cookie, t)
check(404, r1, t)
// verify redirect when correct state provided
s2 := encodeState(&prov, getSid(sess.Store, &prov, t), "google", "/resource", t)
r2, l2 := get(m0, "/oauth-redirect-google?state="+s2, cookie, t)
check(302, r2, t)
if !strings.HasPrefix(l2, "https://accounts.google.com/o/oauth2/auth?client_id=") {
t.Errorf("redirect should be to google, got: %s", l2)
}
}
示例12: runAPI
func runAPI(wg *sync.WaitGroup) {
mux := goji.NewMux()
// List all webhooks
mux.HandleFuncC(
pat.Get("/webhooks"),
func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
ui := uhttp.UI{ctx, r, w}
kase := usecase.ListWebhooks{
DB: &drivers.DB,
Out: &ui,
}
if err := kase.Exec(); err != nil {
fail(err)
}
},
)
// Create a new webhook
mux.HandleFuncC(
pat.Post("/webhooks"),
func(ctx context.Context, w http.ResponseWriter, r *http.Request) {},
)
// Delete a webhook
mux.HandleFuncC(
pat.Delete("/webhooks/:id"),
func(ctx context.Context, w http.ResponseWriter, r *http.Request) {},
)
http.ListenAndServe("localhost:8000", mux)
wg.Done()
}
示例13: Handler
func (s *Server) Handler() http.Handler {
mux := goji.NewMux()
mux.HandleFuncC(pat.Get("/healthcheck"), func(c context.Context, w http.ResponseWriter, r *http.Request) {
w.Write([]byte("ok\n"))
})
return mux
}
示例14: TestCheckFnGood
func TestCheckFnGood(t *testing.T) {
// setup test oauth server
server := httptest.NewServer(newOauthlibServer(t))
defer server.Close()
// set oauth2context HTTPClient to force oauth2 Exchange to use it
client := newClient(server.URL)
oauth2Context = context.WithValue(oauth2Context, oauth2.HTTPClient, client)
// build oauthmw
prov := newProvider()
sess := newSession()
prov.Path = "/"
prov.Configs = map[string]*oauth2.Config{
"oauthlib": newOauthlibEndpoint(server.URL),
}
// setup mux and middleware
m0 := goji.NewMux()
m0.UseC(sess.Handler)
m0.UseC(prov.RequireLogin(newCheckFunc(true, t)))
m0.HandleFuncC(pat.Get("/*"), okHandler)
// do initial request to establish session
r0, l0 := get(m0, "/", nil, t)
check(302, r0, t)
cookie := getCookie(r0, t)
// do redirect
r1, l1 := get(m0, l0, cookie, t)
check(302, r1, t)
urlParse(l1, t)
if !strings.HasPrefix(l1, server.URL) {
t.Fatalf("should be server.URL, got: %s", l0)
}
// do authorization
resp, err := client.Get(l1)
u1 := checkAuthResp(resp, err, t)
// change path due to hard coded values in
// oauthlib/example.TestStorage
u1.Path = "/oauth-login"
// do oauth-login
r2, l2 := get(m0, u1.String(), cookie, t)
check(301, r2, t)
// verify redirect resource path is same as original request
if "/" != l2 {
t.Errorf("redirect path should be /, got: %s", l2)
}
// check original resource path now passes to 'OK' handler
r3, _ := get(m0, "/", cookie, t)
checkOK(r3, t)
// reset context
oauth2Context = oauth2.NoContext
}
示例15: main
func main() {
stderrBackend := logging.NewLogBackend(os.Stderr, "", 0)
stderrFormatter := logging.NewBackendFormatter(stderrBackend, stdout_log_format)
logging.SetBackend(stderrFormatter)
logging.SetFormatter(stdout_log_format)
log.Info("Starting app")
log.Debug("version: %s", version)
if !strings.ContainsRune(version, '-') {
log.Warning("once you tag your commit with name your version number will be prettier")
}
log.Info("Listening at %s", listenAddr)
mux := goji.NewMux()
mux.HandleFuncC(pat.Get("/hello/:name"), hello)
mux.HandleFuncC(pat.Get("/"), requestDump)
http.ListenAndServe(listenAddr, mux)
}