本文整理汇总了Golang中goji/io/pat.Get函数的典型用法代码示例。如果您正苦于以下问题:Golang Get函数的具体用法?Golang Get怎么用?Golang Get使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Get函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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))
}
开发者ID:XANi,项目名称:toolbox,代码行数:25,代码来源:main.go
示例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)
}
开发者ID:knq,项目名称:oauthmw,代码行数:35,代码来源:provider_test.go
示例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)
}
开发者ID:xmattstrongx,项目名称:gostuff,代码行数:7,代码来源:main.go
示例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)
}
开发者ID:upitau,项目名称:goinbigdata,代码行数:7,代码来源:main.go
示例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))
}
开发者ID:dimiro1,项目名称:experiments,代码行数:8,代码来源:main.go
示例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
}
开发者ID:andrew-d,项目名称:go-webapp-skeleton,代码行数:8,代码来源:router.go
示例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))
}
开发者ID:jekyll,项目名称:dashboard,代码行数:9,代码来源:dashboard.go
示例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)
}
开发者ID:funnythingz,项目名称:try-gae-go,代码行数:9,代码来源:app.go
示例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)
}
}
开发者ID:knq,项目名称:oauthmw,代码行数:57,代码来源:provider_test.go
示例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))
}
开发者ID:pkdevboxy,项目名称:dashboard-1,代码行数:13,代码来源:dashboard.go
示例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)
}
}
开发者ID:knq,项目名称:oauthmw,代码行数:35,代码来源:provider_test.go
示例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()
}
开发者ID:nullstyle,项目名称:coinop,代码行数:34,代码来源:serve.go
示例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
}
开发者ID:carriercomm,项目名称:veneur,代码行数:7,代码来源:http.go
示例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
}
开发者ID:knq,项目名称:oauthmw,代码行数:60,代码来源:provider_test.go
示例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)
}
开发者ID:XANi,项目名称:web-toolbox,代码行数:17,代码来源:toolbox.go
示例16: initMux
func initMux(driver federation.Driver) *goji.Mux {
mux := goji.NewMux()
c := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedHeaders: []string{"*"},
AllowedMethods: []string{"GET"},
})
mux.Use(c.Handler)
fed := &federation.Handler{driver}
mux.Handle(pat.Get("/federation"), fed)
mux.Handle(pat.Get("/federation/"), fed)
return mux
}
开发者ID:stellar,项目名称:bridge-server,代码行数:17,代码来源:main.go
示例17: API
func API() *goji.Mux {
mux := goji.SubMux()
// We pass the routes as relative to the point where the API router
// will be mounted. The super-router will strip any prefix off for us.
mux.HandleFuncC(pat.Get("/people"), api.ListPeople)
mux.HandleFuncC(pat.Post("/people"), api.CreatePerson)
mux.HandleFuncC(pat.Get("/people/:person"), api.GetPerson)
mux.HandleFuncC(pat.Delete("/people/:person"), api.DeletePerson)
// Add default 'not found' route that responds with JSON
mux.HandleFunc(pat.New("/*"), func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(404)
fmt.Fprint(w, `{"error":"not found"}`)
})
return mux
}
开发者ID:andrew-d,项目名称:go-webapp-skeleton,代码行数:18,代码来源:router.go
示例18: List
// List registers a `GET /resource` handler for the resource
func (res *Resource) List(storage store.List) {
res.HandleFuncC(
pat.Get(patRoot),
func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
res.listHandler(ctx, w, r, storage)
},
)
res.addRoute(get, patRoot)
}
开发者ID:samikoskinen,项目名称:go-json-spec-handler,代码行数:11,代码来源:resource.go
示例19: TestMetrics
func TestMetrics(t *testing.T) {
backend := &stubBackend{}
metrics.SetBackend(backend)
inner := goji.NewMux()
inner.HandleFunc(pat.Get("/:baz"), func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(1)
})
inner.UseC(metrics.WrapSubmuxC)
outer := goji.NewMux()
outer.HandleFunc(pat.Get("/foo"), func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(2)
})
outer.HandleC(pat.New("/bar/*"), inner)
outer.UseC(metrics.WrapC)
cases := []struct {
path string
expect map[string]int
}{
{"/foo", map[string]int{"foo.request": 1, "foo.response.2": 1}},
{"/bar/baz", map[string]int{"bar.:baz.request": 1, "bar.:baz.response.1": 1}},
{"/bar", map[string]int{}},
}
for _, testcase := range cases {
backend.Reset()
req, err := http.NewRequest("GET", testcase.path, nil)
if err != nil {
t.Fatal(err)
}
rr := httptest.NewRecorder()
outer.ServeHTTPC(context.Background(), rr, req)
if have, want := backend.data, testcase.expect; !reflect.DeepEqual(have, want) {
t.Errorf("%s: Expected %#v but got %#v", testcase.path, want, have)
}
}
}
开发者ID:antifuchs,项目名称:saypi,代码行数:41,代码来源:metrics_test.go
示例20: Action
// Action allows you to add custom actions to your resource types, it uses the
// GET /(prefix/)resourceTypes/:id/<actionName> path format
func (res *Resource) Action(actionName string, storage store.Get) {
matcher := path.Join(patID, actionName)
res.HandleFuncC(
pat.Get(matcher),
func(ctx context.Context, w http.ResponseWriter, r *http.Request) {
res.actionHandler(ctx, w, r, storage)
},
)
res.addRoute(patch, matcher)
}
开发者ID:samikoskinen,项目名称:go-json-spec-handler,代码行数:14,代码来源:resource.go
注:本文中的goji/io/pat.Get函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论