split into multi files

This commit is contained in:
codeskyblue
2016-07-23 23:48:46 +08:00
parent 162ed5fa97
commit 204422ad86
2 changed files with 30 additions and 28 deletions

30
httpstaticserver.go Normal file
View File

@@ -0,0 +1,30 @@
package main
import (
"net/http"
"github.com/gorilla/mux"
)
type HTTPStaticServer struct {
Root string
m *mux.Router
}
func NewHTTPStaticServer(root string) *HTTPStaticServer {
m := mux.NewRouter()
s := &HTTPStaticServer{
Root: root,
m: m,
}
m.HandleFunc("/", s.hIndex)
return s
}
func (s *HTTPStaticServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.m.ServeHTTP(w, r)
}
func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello world!"))
}

28
main.go
View File

@@ -6,7 +6,6 @@ import (
"strconv"
"github.com/alecthomas/kingpin"
"github.com/gorilla/mux"
)
type Configure struct {
@@ -19,33 +18,6 @@ type Configure struct {
var gcfg = Configure{}
func FileHandler(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "unknown")
}
type HTTPStaticServer struct {
Root string
m *mux.Router
}
func NewHTTPStaticServer(root string) *HTTPStaticServer {
m := mux.NewRouter()
s := &HTTPStaticServer{
Root: root,
m: m,
}
m.HandleFunc("/", s.hIndex)
return s
}
func (s *HTTPStaticServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
s.m.ServeHTTP(w, r)
}
func (s *HTTPStaticServer) hIndex(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Hello world!"))
}
func parseFlags() {
kingpin.HelpFlag.Short('h')
kingpin.Flag("addr", "listen address").Short('a').Default(":8000").StringVar(&gcfg.Addr)