本文整理汇总了Golang中github.com/paulbellamy/mango.Stack类的典型用法代码示例。如果您正苦于以下问题:Golang Stack类的具体用法?Golang Stack怎么用?Golang Stack使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Stack类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestProducer
func TestProducer(t *testing.T) {
stack := new(mango.Stack)
handler := stack.HandlerFunc(pact.Producer)
testflight.WithServer(handler, func(r *testflight.Requester) {
pact_str, err := ioutil.ReadFile("../pacts/my_consumer-my_producer.json")
if err != nil {
t.Error(err)
}
pacts := make(map[string]interface{})
err = json.Unmarshal(pact_str, &pacts)
if err != nil {
t.Error(err)
}
for _, i := range pacts["interactions"].([]interface{}) {
interaction := i.(map[string]interface{})
t.Logf("Given %s", interaction["producer_state"])
t.Logf(" %s", interaction["description"])
request := interaction["request"].(map[string]interface{})
var actualResponse *testflight.Response
switch request["method"] {
case "get":
actualResponse = r.Get(request["path"].(string) + "?" + request["query"].(string))
}
expectedResponse := interaction["response"].(map[string]interface{})
assert.Equal(t, int(expectedResponse["status"].(float64)), actualResponse.StatusCode)
for k, v := range expectedResponse["headers"].(map[string]interface{}) {
assert.Equal(t, v, actualResponse.RawResponse.Header[k][0])
}
responseBody := make(map[string]interface{})
err = json.Unmarshal([]byte(actualResponse.Body), &responseBody)
if err != nil {
t.Error(err)
}
for _, diff := range pretty.Diff(expectedResponse["body"], responseBody) {
t.Log(diff)
}
assert.Equal(t, expectedResponse["body"], responseBody)
}
})
}
开发者ID:uglyog,项目名称:example_pact_with_go,代码行数:49,代码来源:producer_test.go
示例2: TestFilter
func TestFilter(t *testing.T) {
stack := new(mango.Stack)
stack.Middleware(Authenticated)
ts := httptest.NewServer(streamango.FilteredFunc(stack, stream, &F{}))
defer ts.Close()
for _, tc := range fcases {
res, err := http.Get(ts.URL + tc.url)
if err != nil {
t.Fatal(err)
}
got, err := ioutil.ReadAll(res.Body)
if err != nil {
t.Fatal(err)
}
if string(got) != tc.expected {
t.Errorf("got %q, want %q", string(got), tc.expected)
}
}
}
开发者ID:sunfmin,项目名称:streamango,代码行数:21,代码来源:whole_test.go
示例3: main
func main() {
// Pull in command line options or defaults if none given
flag.Parse()
f, err := os.OpenFile(*skylib.LogFileName, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0666)
if err == nil {
defer f.Close()
log.SetOutput(f)
}
skylib.Setup(sName)
homeTmpl = template.MustParse(homeTemplate, nil)
respTmpl = template.MustParse(responseTemplate, nil)
rpc.HandleHTTP()
portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)
stack := new(mango.Stack)
stack.Address = portString
routes := make(map[string]mango.App)
routes["/"] = homeHandler
routes["/new"] = submitHandler
stack.Middleware(mango.Routing(routes))
stack.Run(nil)
}
开发者ID:paulbellamy,项目名称:skynet,代码行数:28,代码来源:mangoInitiator.go
示例4: main
func main() {
stack := new(mango.Stack)
stack.Address = ":3300"
// Route all requests for /goodbye to the Goodbye handler
routes := map[string]mango.App{"/goodbye(.*)": Goodbye}
stack.Middleware(mango.Routing(routes))
stack.Middleware(mango.ShowErrors("ERROR!!"))
//stack.Run(Hello)
fmt.Println("type of stack: ", reflect.TypeOf(stack))
//fmt.Println("type of m: ", reflect.TypeOf(m))
fmt.Println("type of hello: ", reflect.TypeOf(Hello))
var x float64 = 3.4
v := reflect.ValueOf(x)
fmt.Println("type:", v.Type())
fmt.Println("kind is float64:", v.Kind() == reflect.Float64)
fmt.Println("value:", v.Float())
type T struct {
A int
B string
}
t := T{23, "skidoo"}
s := reflect.ValueOf(&t).Elem()
typeOfT := s.Type()
for i := 0; i < s.NumField(); i++ {
f := s.Field(i)
fmt.Printf("%d: %s %s = %v\n", i,
typeOfT.Field(i).Name, f.Type(), f.Interface())
}
}
开发者ID:hfeeki,项目名称:bingo,代码行数:33,代码来源:hello.go
示例5: FilteredFunc
func FilteredFunc(stack *mango.Stack, streamer http.HandlerFunc, filter BodyFilter) http.HandlerFunc {
compiled_app := stack.Compile(streamerapp(streamer))
return func(w http.ResponseWriter, r *http.Request) {
env := make(map[string]interface{})
env["mango.request"] = &mango.Request{r}
env["mango.bodyfilter"] = filter
env["mango.writer"] = w
status, headers, body := compiled_app(env)
_, streaming := env["streamango.streaming"]
// streaming, so don't need to do
if streaming {
return
}
for key, values := range headers {
for _, value := range values {
w.Header().Add(key, value)
}
}
w.WriteHeader(int(status))
w.Write([]byte(body))
}
}
开发者ID:sunfmin,项目名称:streamango,代码行数:24,代码来源:filter.go
示例6: main
func main() {
stack := new(mango.Stack)
stack.Address = ":" + os.Getenv("PORT")
// Route all requests for /goodbye to the Goodbye handler
routes := map[string]mango.App{"/goodbye(.*)": Goodbye}
stack.Middleware(mango.Routing(routes))
// Hello handles all requests not sent to Goodbye
stack.Run(Hello)
}
开发者ID:kashdan,项目名称:esther_go,代码行数:11,代码来源:app.go
示例7: StartServer
func StartServer() {
routes := make(map[string]mango.App)
routes["/hello"] = new(mango.Stack).Compile(hello)
routes["/bye"] = new(mango.Stack).Compile(bye)
testServer := new(mango.Stack)
testServer.Middleware(mango.ShowErrors("<html><body>{Error|html}</body></html>"), mango.Routing(routes))
testServer.Address = "localhost:" + Configuration.Server_Port
testServer.Run(routeNotFound)
fmt.Printf("Running server on: %s\n", testServer.Address)
}
开发者ID:bryanjos,项目名称:goken,代码行数:11,代码来源:server.go
示例8: main
func main() {
// Pull in command line options or defaults if none given
flag.Parse()
skylib.NewAgent().Start()
homeTmpl = template.MustParse(homeTemplate, nil)
respTmpl = template.MustParse(responseTemplate, nil)
portString := fmt.Sprintf("%s:%d", *skylib.BindIP, *skylib.Port)
stack := new(mango.Stack)
stack.Address = portString
routes := make(map[string]mango.App)
routes["/"] = homeHandler
routes["/new"] = submitHandler
stack.Middleware(mango.Routing(routes))
stack.Run(nil)
}
开发者ID:andradeandrey,项目名称:skynet,代码行数:20,代码来源:mangoInitiator.go
示例9: Mux
func Mux() (mux *http.ServeMux) {
p := pat.New()
sessionMW := mango.Sessions("f908b1c425062e95d30b8d30de7123458", "duoerl", &mango.CookieOptions{Path: "/", MaxAge: 3600 * 24 * 7})
rendererMW := middlewares.ProduceRenderer()
authenMW := middlewares.AuthenticateUser()
hardAuthenMW := middlewares.HardAuthenUser()
rHtml, rJson := middlewares.RespondHtml(), middlewares.RespondJson()
mainLayoutMW := middlewares.ProduceLayout(middlewares.MAIN_LAYOUT)
mainStack := new(mango.Stack)
mainStack.Middleware(mangogzip.Zipper, mangolog.Logger, sessionMW, authenMW, mainLayoutMW, rendererMW, rHtml)
mainAjaxStack := new(mango.Stack)
mainAjaxStack.Middleware(mangogzip.Zipper, mangolog.Logger, sessionMW, authenMW, rJson)
hardAuthenStack := new(mango.Stack)
hardAuthenStack.Middleware(mangogzip.Zipper, mangolog.Logger, sessionMW, hardAuthenMW, mainLayoutMW, rendererMW, rHtml)
// User
p.Get("/login", mainStack.HandlerFunc(sessions.LoginPage))
p.Post("/login", mainStack.HandlerFunc(sessions.LoginAction))
p.Get("/signup", mainStack.HandlerFunc(sessions.SignupPage))
p.Post("/signup", mainStack.HandlerFunc(sessions.SignupAction))
p.Get("/logout", mainStack.HandlerFunc(sessions.Logout))
p.Post("/user/update", hardAuthenStack.HandlerFunc(users.Update))
p.Get("/user/edit", hardAuthenStack.HandlerFunc(users.Edit))
p.Get("/user/:id", mainStack.HandlerFunc(users.Show))
// User post
p.Post("/post/create", mainAjaxStack.HandlerFunc(posts.Create))
// Brand
p.Get("/brands", mainStack.HandlerFunc(brands.Index))
p.Get("/brand/new", mainStack.HandlerFunc(brands.New))
p.Post("/brand/create", mainStack.HandlerFunc(brands.Create))
p.Get("/brand/:id", mainStack.HandlerFunc(brands.Show))
p.Get("/brand/:id/edit", mainStack.HandlerFunc(brands.Edit))
p.Post("/brand/update", mainStack.HandlerFunc(brands.Update))
// Follow brand
p.Post("/brand/follow", mainStack.HandlerFunc(followbrands.Create))
p.Post("/brand/unfollow", mainStack.HandlerFunc(followbrands.Delete))
// Product
p.Get("/products", mainStack.HandlerFunc(products.Index))
p.Get("/product/new", mainStack.HandlerFunc(products.New))
p.Post("/product/create", mainStack.HandlerFunc(products.Create))
p.Get("/product/:id", mainStack.HandlerFunc(products.Show))
p.Get("/product/:id/edit", mainStack.HandlerFunc(products.Edit))
p.Post("/product/update", mainStack.HandlerFunc(products.Update))
// Notes
p.Get("/note/new", mainStack.HandlerFunc(notes.New))
p.Get("/note/:id", mainStack.HandlerFunc(notes.Show))
p.Post("/note/create", mainStack.HandlerFunc(notes.Create))
// Review
p.Post("/review/create", mainStack.HandlerFunc(reviews.Create))
p.Post("/review/like", mainAjaxStack.HandlerFunc(reviews.Like))
// Wish Item
p.Post("/wish_item/add", mainAjaxStack.HandlerFunc(wishitems.Create))
p.Post("/wish_item/remove", mainAjaxStack.HandlerFunc(wishitems.Delete))
// Own Item
p.Post("/own_item/add", mainAjaxStack.HandlerFunc(ownitems.Create))
p.Post("/own_item/remove", mainAjaxStack.HandlerFunc(ownitems.Delete))
// News
p.Get("/news/:id", mainStack.HandlerFunc(news.Show))
p.Post("/news/create", mainStack.HandlerFunc(news.Create))
p.Get("/news/:id/edit", mainStack.HandlerFunc(news.Edit))
p.Post("/news/update", mainStack.HandlerFunc(news.Update))
// For admin in the futrue
p.Get("/admin/categories", mainStack.HandlerFunc(categories.Index))
p.Post("/admin/category/create", mainStack.HandlerFunc(categories.Create))
p.Post("/admin/efficacy/create", mainStack.HandlerFunc(efficacies.Create))
// News for admin
p.Get("/admin/news/new", mainStack.HandlerFunc(news.New))
// For Image upload
imageUploader := tenpu.MakeUploader(images.TheImageMaker)
imageLoader := tenpu.MakeFileLoader(images.TheImageMaker)
p.Post("/upload/:category/:uid", imageUploader)
p.Get("/img/:id/:name", imageLoader)
p.Get("/", mainStack.HandlerFunc(feeds.Index))
mux = http.NewServeMux()
mux.HandleFunc("/favicon.ico", filterUrl)
mux.Handle("/", p)
mux.Handle("/public/", http.FileServer(http.Dir(".")))
train.ConfigureHttpHandler(mux)
return
//.........这里部分代码省略.........
开发者ID:kobeld,项目名称:duoerl,代码行数:101,代码来源:routes.go
示例10: main
func main() {
stack := new(mango.Stack)
stack.Address = ":3000"
stack.Middleware(mango.ShowErrors(""))
stack.Run(pact.Producer)
}
开发者ID:uglyog,项目名称:example_pact_with_go,代码行数:6,代码来源:main.go
注:本文中的github.com/paulbellamy/mango.Stack类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论