Rewrite the local server in Go
This commit is contained in:
parent
c43c319d26
commit
f3f319ccce
18
tools/serve
18
tools/serve
@ -1,17 +1,3 @@
|
|||||||
#!/usr/bin/python
|
#!/bin/bash
|
||||||
|
|
||||||
import SimpleHTTPServer
|
exec go run tools/serve.go
|
||||||
import SocketServer
|
|
||||||
import os
|
|
||||||
|
|
||||||
PORT = 8000
|
|
||||||
|
|
||||||
public_dir = os.path.join(os.path.dirname(__file__), '..', 'public')
|
|
||||||
os.chdir(public_dir)
|
|
||||||
|
|
||||||
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
|
|
||||||
Handler.extensions_map.update({
|
|
||||||
'': 'text/html',
|
|
||||||
});
|
|
||||||
httpd = SocketServer.TCPServer(("", PORT), Handler)
|
|
||||||
httpd.serve_forever()
|
|
||||||
|
15
tools/serve.go
Normal file
15
tools/serve.go
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
port := "8000"
|
||||||
|
publicDir := "public"
|
||||||
|
fmt.Printf("Serving Go by Example at http://127.0.0.1:%s\n", port)
|
||||||
|
|
||||||
|
// Simple static webserver:
|
||||||
|
http.ListenAndServe(":"+port, http.FileServer(http.Dir(publicDir)))
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user