package main import ( "log" "net/http" "os" "path" ) type Server struct { fs http.Handler ws *WS } func New() *Server { fs := http.FileServer(http.Dir(config().GetString("d"))) return &Server{ fs: fs, ws: NewWS(), } } func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) { log.Println("ext", path.Ext(r.URL.Path)) if path.Ext(r.URL.Path) != "" { s.fs.ServeHTTP(w, r) } else if _, err := os.Stat(path.Join(config().GetString("d"), r.URL.Path[1:])); os.IsNotExist(err) { s.ws.ServeHTTP(w, r) } else { s.fs.ServeHTTP(w, r) } }