1. Alexander Gallego
  2. plex

Overview

HTTPS SSH
* A demultiplexer for web requests. Written for the go programming language. See golang.org for more details about the language. 
* The goal is to have a small and powerful regexp router with registered functions for pre and post processing.

=====================================
See the testing package for more info
=====================================



func TestGETOverridingDefault(t *testing.T) {
	counter := 3
	forwarder := func(w http.ResponseWriter, r *RequestForwarder) { counter-- }
	functionNormal := func(w http.ResponseWriter, r *http.Request) { counter-- }

	plex := New()

	plex.HandleFunc("/", functionNormal).
		AppendPreRouteFunc(forwarder).
		AppendPostRouteFunc(forwarder).
		VerbHandlerFunc("GET", functionNormal)

	// run server
	ts := httptest.NewServer(plex)
	defer ts.Close()
	http.Get(ts.URL + "/")

	if counter != 0 {
		t.Fatalf("Counter is not 0, means that either thepre-route, post-route or main didn't get executed")
	}
}







=====================================
Full Program:
=====================================

package main

import (
	"fmt"
	"bitbucket.org/agallego/log"
	"bitbucket.org/agallego/plex"
	"net/http"
	"time"
)

func main() {
	mux := plex.New()
	mux.HandleFunc("/", helloWorld)
	s := &http.Server{
		Addr:           ":8080",
		Handler:        mux,              //multiplexer/demultiplexer
		ReadTimeout:    10 * time.Second, //1 minute
		WriteTimeout:   10 * time.Second, //1 minute
		MaxHeaderBytes: 1 << 20,
	}
	log.Fatal("Error listenting for Connection %v", s.ListenAndServe())

}

func helloWorld(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "hello world")
}