Permalink
Browse files

Removing older files

  • Loading branch information...
1 parent 938e823 commit 2a0266f13cd4806f0be0b90eb6a3ecce31947531 @paulbellamy committed May 21, 2011
Showing with 0 additions and 113 deletions.
  1. +0 −65 middleware.go
  2. +0 −48 temp.go
View
@@ -1,65 +0,0 @@
-package main
-
-import (
- "fmt"
-)
-
-// This is the core app the user has written
-type MangoApp func(string) string
-
-// These are pieces of middleware,
-// which 'wrap' around the core MangoApp
-// (and each other)
-type MangoMiddleware func(string, MangoApp) string
-
-// Bundle a given list of MangoMiddleware pieces into a MangoApp
-func Bundle(r ...MangoMiddleware) MangoApp {
- if len(r) <= 1 {
- // Terminate the innermost piece of MangoMiddleware
- // Basically stops it from recursing any further.
- return func(input string) string {
- return r[0](input, func(string) string {
- return ""
- })
- }
- }
- return wrap(r[0], Bundle(r[1:]...))
-}
-
-// Attach a piece of MangoMiddleware to the outside
-// of a MangoApp. This wraps the inner MangoApp
-// inside the outer MangoMiddleware.
-func wrap(middleware MangoMiddleware, app MangoApp) MangoApp {
- return func(input string) string {
- return middleware(input, app)
- }
-}
-
-// Convert a MangoApp into MangoMiddleware
-// We convert the core app into a MangoMiddleware
-// so we can pass it to Bundle as part of the
-// stack. Because the MangoApp does not call its
-// upstream method, the resulting MangoMiddleware
-// will just ignore any upstream passed to it.
-func middlewareify(app MangoApp) MangoMiddleware {
- return func(input string, upstream MangoApp) string {
- return app(input)
- }
-}
-
-func Sessions(in string, app MangoApp) string {
- return fmt.Sprintf("Sessions\n%s\nSessions", app(in))
-}
-
-func Logger(in string, app MangoApp) string {
- return fmt.Sprintf("Logger\n%s\nLogger", app(in))
-}
-
-func Hello(in string) string {
- return "Hello World!"
-}
-
-func main() {
- app := Bundle(Sessions, Logger, middlewareify(Hello))
- fmt.Printf(app(""))
-}
View
48 temp.go
@@ -1,48 +0,0 @@
-package main
-
-import (
- "fmt"
- "http"
- "log"
- "os"
- "time"
-)
-
-type MangoApp func(map[string]interface{}) (int, map[string]string, string)
-
-type Mango struct {
- app MangoApp
-}
-
-func (this *Mango) BuildStack() http.HandlerFunc {
- return func(w http.ResponseWriter, r *http.Request) {
- env := make(map[string]interface{})
- status, headers, body := this.app(env)
- w.WriteHeader(status)
- for key, value := range headers {
- w.Header().Set(key, value)
- }
- fmt.Fprintf(w, body)
- }
-}
-
-func (this *Mango) App(app MangoApp) (os.Error) {
- this.app = app
- return nil
-}
-
-func (this *Mango) Run(address string) (os.Error) {
- log.Println("Starting Mango Server On:", address)
- http.HandleFunc("/", this.BuildStack())
- return http.ListenAndServe(address , nil)
-}
-
-func Hello(map[string]interface{}) (int, map[string]string, string) {
- return 200, map[string]string{"Content-Type": "text/html"}, fmt.Sprintf("%d", time.Seconds())
-}
-
-func main() {
- mango := new(Mango)
- mango.App(Hello)
- mango.Run("0.0.0.0:8080")
-}

0 comments on commit 2a0266f

Please sign in to comment.