Skip to content

Commit

Permalink
Catz example for cats_middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Castell committed Oct 22, 2011
1 parent 70a5fe6 commit 301e3e2
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 4 additions & 4 deletions examples/Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
42 changes: 42 additions & 0 deletions examples/cats.go
Original file line number Diff line number Diff line change
@@ -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.