split into multi files
This commit is contained in:
30
httpstaticserver.go
Normal file
30
httpstaticserver.go
Normal 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
28
main.go
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user