You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

67 lines
2.1 KiB

11 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. package weed_server
  2. import (
  3. "net/http"
  4. "strconv"
  5. "github.com/chrislusf/weed-fs/go/filer"
  6. "github.com/chrislusf/weed-fs/go/filer/cassandra_store"
  7. "github.com/chrislusf/weed-fs/go/filer/embedded_filer"
  8. "github.com/chrislusf/weed-fs/go/filer/flat_namespace"
  9. "github.com/chrislusf/weed-fs/go/filer/redis_store"
  10. "github.com/chrislusf/weed-fs/go/glog"
  11. "github.com/chrislusf/weed-fs/go/security"
  12. )
  13. type FilerServer struct {
  14. port string
  15. master string
  16. collection string
  17. defaultReplication string
  18. redirectOnRead bool
  19. disableDirListing bool
  20. secret security.Secret
  21. filer filer.Filer
  22. }
  23. func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string,
  24. replication string, redirectOnRead bool, disableDirListing bool,
  25. secret string,
  26. cassandra_server string, cassandra_keyspace string,
  27. redis_server string, redis_database int,
  28. ) (fs *FilerServer, err error) {
  29. fs = &FilerServer{
  30. master: master,
  31. collection: collection,
  32. defaultReplication: replication,
  33. redirectOnRead: redirectOnRead,
  34. disableDirListing: disableDirListing,
  35. port: ":" + strconv.Itoa(port),
  36. }
  37. if cassandra_server != "" {
  38. cassandra_store, err := cassandra_store.NewCassandraStore(cassandra_keyspace, cassandra_server)
  39. if err != nil {
  40. glog.Fatalf("Can not connect to cassandra server %s with keyspace %s: %v", cassandra_server, cassandra_keyspace, err)
  41. }
  42. fs.filer = flat_namespace.NewFlatNamesapceFiler(master, cassandra_store)
  43. } else if redis_server != "" {
  44. redis_store := redis_store.NewRedisStore(redis_server, redis_database)
  45. fs.filer = flat_namespace.NewFlatNamesapceFiler(master, redis_store)
  46. } else {
  47. if fs.filer, err = embedded_filer.NewFilerEmbedded(master, dir); err != nil {
  48. glog.Fatalf("Can not start filer in dir %s : %v", dir, err)
  49. return
  50. }
  51. r.HandleFunc("/admin/mv", fs.moveHandler)
  52. }
  53. r.HandleFunc("/", fs.filerHandler)
  54. return fs, nil
  55. }
  56. func (fs *FilerServer) jwt(fileId string) security.EncodedJwt {
  57. return security.GenJwt(fs.secret, fileId)
  58. }