2014-03-30 18:28:04 +00:00
|
|
|
package weed_server
|
|
|
|
|
|
|
|
import (
|
2014-04-09 16:44:58 +00:00
|
|
|
"code.google.com/p/weed-fs/go/filer"
|
|
|
|
"code.google.com/p/weed-fs/go/glog"
|
2014-03-30 18:28:04 +00:00
|
|
|
"net/http"
|
2014-03-31 03:57:25 +00:00
|
|
|
"strconv"
|
2014-03-30 18:28:04 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type FilerServer struct {
|
|
|
|
port string
|
|
|
|
master string
|
|
|
|
collection string
|
2014-04-09 16:44:58 +00:00
|
|
|
filer filer.Filer
|
2014-03-30 18:28:04 +00:00
|
|
|
}
|
|
|
|
|
2014-03-31 03:57:25 +00:00
|
|
|
func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string) (fs *FilerServer, err error) {
|
2014-03-30 18:28:04 +00:00
|
|
|
fs = &FilerServer{
|
|
|
|
master: master,
|
2014-03-31 03:57:25 +00:00
|
|
|
collection: collection,
|
|
|
|
port: ":" + strconv.Itoa(port),
|
2014-03-30 18:28:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-18 05:33:21 +00:00
|
|
|
if fs.filer, err = filer.NewFilerEmbedded(master, dir); err != nil {
|
2014-04-10 04:01:48 +00:00
|
|
|
glog.Fatal("Can not start filer in dir", dir, ": ", err.Error())
|
2014-03-30 18:28:04 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
r.HandleFunc("/", fs.filerHandler)
|
|
|
|
|
|
|
|
return fs, nil
|
|
|
|
}
|