Commit 1e6cbdea authored by Anders Mundt Due (work)'s avatar Anders Mundt Due (work)
Browse files

preliminary ideas

parent 75192b40
......@@ -2,44 +2,58 @@
package main
import (
"fmt"
"log"
"net/http"
"sync"
"fmt"
"log"
"net/http"
"sync"
)
var mu sync.Mutex
var count int
func main() {
http.HandleFunc("/", handler) // handle most requests
http.HandleFunc("/stats", counter) // counter print
log.Fatal(http.ListenAndServe("localhost:8000", nil))
http.HandleFunc("/", handler) // handle most requests
http.HandleFunc("/stats", counter) // counter print
http.HandleFunc("/file", filer) // file getter
log.Fatal(http.ListenAndServe("localhost:8000", nil))
}
// handler echo the Path component of the requested url
func handler(w http.ResponseWriter, r *http.Request) {
mu.Lock()
count++
mu.Unlock()
fmt.Fprintf(w, "%s %s %s\n", r.Method, r.URL, r.Proto)
for k, v := range r.Header {
fmt.Fprintf(w, "Header[%q] = %q\n", k, v)
}
fmt.Fprintf(w, "Host = %q\n", r.Host)
fmt.Fprintf(w, "RemoteAddr = %q\n", r.RemoteAddr)
if err := r.ParseForm(); err != nil {
log.Print(err)
}
for k, v := range r.Form {
fmt.Fprintf(w, "Form[%q] = %q\n", k, v)
}
fmt.Fprintf(w, "URL.Path = %q\n", r.URL.Path)
mu.Lock()
count++
mu.Unlock()
fmt.Fprintf(w, "%s %s %s\n", r.Method, r.URL, r.Proto)
for k, v := range r.Header {
fmt.Fprintf(w, "Header[%q] = %q\n", k, v)
}
fmt.Fprintf(w, "Host = %q\n", r.Host)
fmt.Fprintf(w, "RemoteAddr = %q\n", r.RemoteAddr)
if err := r.ParseForm(); err != nil {
log.Print(err)
}
for k, v := range r.Form {
fmt.Fprintf(w, "Form[%q] = %q\n", k, v)
}
fmt.Fprintf(w, "URL.Path = %q\n", r.URL.Path)
}
// counter printer
func counter(w http.ResponseWriter, r *http.Request) {
mu.Lock()
fmt.Fprintf(w, "Count %d\n", count)
mu.Unlock()
mu.Lock()
fmt.Fprintf(w, "Count %d\n", count)
mu.Unlock()
}
// file getter
func filer(w http.ResponseWriter, r *http.Request) {
mu.Lock()
// stat file
// if not cached or old
// open file
// read file
// cache file
// use cache
mu.Unlock()
// send file to w
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment