Skip to content

Instantly share code, notes, and snippets.

@parnurzeal
Created December 11, 2014 09:06
Show Gist options
  • Save parnurzeal/c4325d593fdbe2601d9c to your computer and use it in GitHub Desktop.
Save parnurzeal/c4325d593fdbe2601d9c to your computer and use it in GitHub Desktop.
testets
package main
import (
"bufio"
"fmt"
"io"
"net"
"net/http"
)
/*func homeHandler(w http.ResponseWriter, r *http.Request) {
go func() {
http.ServeFile(w, r, r.URL.Path[1:])
time.Sleep(5 * time.Second)
}()
}*/
func main() {
ln, err := net.Listen("tcp", ":8000")
if err != nil {
panic(err)
}
for {
conn, err := ln.Accept()
if err != nil {
fmt.Println(err)
conn.Close()
continue
}
bufReader := bufio.NewReader(conn)
req, err := http.ReadRequest(bufReader)
if err != nil {
fmt.Println(err)
conn.Close()
continue
}
//fmt.Println(req)
upath := req.URL.Path
//dir, file := filepath.Split(upath)
fs := http.Dir(".")
f, err := fs.Open(upath)
if err != nil {
fmt.Println("ERROR", err)
conn.Close()
continue
}
defer f.Close()
d, err := f.Stat()
if err != nil {
fmt.Println(err)
conn.Close()
continue
}
if d.IsDir() {
dirs, err := f.Readdir(
}
fmt.Println(d)
io.Copy(conn, f)
//http.ServeContent(conn, req, d.Name(), d.ModTime(), f)
//fmt.Println(dir, file)
conn.Close()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment