Skip to content
Browse files

Catz example for cats_middleware

  • Loading branch information...
1 parent 70a5fe6 commit 301e3e2537dab3e522543856bf65610a482ee48b @victorcoder victorcoder committed Oct 22, 2011
Showing with 47 additions and 5 deletions.
  1. +1 −1 README.markdown
  2. +4 −4 examples/Makefile
  3. +42 −0 examples/cats.go
View
2 README.markdown
@@ -181,7 +181,7 @@ To use our middleware we would do:
// Initialize our cats middleware with our list of cat_images
cat_images := []string{"ceiling_cat.jpg", "itteh_bitteh_kittehs.jpg", "monorail_cat.jpg"}
- cats_middleware = Cats(cat_images)
+ cats_middleware := Cats(cat_images)
stack.Middleware(cats_middleware) // Include the Cats middleware in our stack
View
8 examples/Makefile
@@ -1,16 +1,16 @@
include $(GOROOT)/src/Make.inc
-BINS=hello logger session routing
+BINS=hello logger session routing cats
LIBS=cats_middleware.a silence_middleware.a
-all: $(BINS) $(LIBS)
+all: $(LIBS) $(BINS)
clean:
rm -rf *.[68] $(BINS)
%: %.go
- $(GC) $*.go
- $(LD) -o $@ $*.$O
+ $(GC) -I _obj $*.go
+ $(LD) -L _obj -o $@ $*.$O
%.a: %.go
$(GC) $*.go
View
42 examples/cats.go
@@ -0,0 +1,42 @@
+package main
+
+import (
+ "mango"
+ "cats_middleware"
+ "http"
+ "os"
+ "io/ioutil"
+)
+
+func Hello(env mango.Env) (mango.Status, mango.Headers, mango.Body) {
+ env.Logger().Println("Got a", env.Request().Method, "request for", env.Request().RawURL)
+
+ response, err := http.Get("http://www.weddinggalleryweb.com/")
+ if err != nil {
+ env.Logger().Printf("%s", err)
+ os.Exit(1)
+ }
+ defer response.Body.Close()
+
+ contents, err := ioutil.ReadAll(response.Body)
+ if err != nil {
+ env.Logger().Printf("%s", err)
+ os.Exit(1)
+ }
+
+ return 200, mango.Headers{}, mango.Body(contents)
+}
+
+func main() {
+
+ stack := new(mango.Stack)
+ stack.Address = ":3000"
+
+ // Initialize our cats middleware with our list of cat_images
+ cat_images := []string{"http://images.cheezburger.com/completestore/2010/7/4/9440dc57-52a6-4122-9ab3-efd4daa0ff60.jpg", "http://images.icanhascheezburger.com/completestore/2008/12/10/128733944185267668.jpg"}
+ cats_middleware := cats.Cats(cat_images)
+
+ stack.Middleware(cats_middleware) // Include the Cats middleware in our stack
+
+ stack.Run(Hello)
+}

0 comments on commit 301e3e2

Please sign in to comment.
Something went wrong with that request. Please try again.