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.

65 lines
2.0 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. secret security.Secret
  20. filer filer.Filer
  21. }
  22. func NewFilerServer(r *http.ServeMux, port int, master string, dir string, collection string,
  23. replication string, redirectOnRead bool,
  24. secret string,
  25. cassandra_server string, cassandra_keyspace string,
  26. redis_server string, redis_database int,
  27. ) (fs *FilerServer, err error) {
  28. fs = &FilerServer{
  29. master: master,
  30. collection: collection,
  31. defaultReplication: replication,
  32. redirectOnRead: redirectOnRead,
  33. port: ":" + strconv.Itoa(port),
  34. }
  35. if cassandra_server != "" {
  36. cassandra_store, err := cassandra_store.NewCassandraStore(cassandra_keyspace, cassandra_server)
  37. if err != nil {
  38. glog.Fatalf("Can not connect to cassandra server %s with keyspace %s: %v", cassandra_server, cassandra_keyspace, err)
  39. }
  40. fs.filer = flat_namespace.NewFlatNamesapceFiler(master, cassandra_store)
  41. } else if redis_server != "" {
  42. redis_store := redis_store.NewRedisStore(redis_server, redis_database)
  43. fs.filer = flat_namespace.NewFlatNamesapceFiler(master, redis_store)
  44. } else {
  45. if fs.filer, err = embedded_filer.NewFilerEmbedded(master, dir); err != nil {
  46. glog.Fatalf("Can not start filer in dir %s : %v", dir, err)
  47. return
  48. }
  49. r.HandleFunc("/admin/mv", fs.moveHandler)
  50. }
  51. r.HandleFunc("/", fs.filerHandler)
  52. return fs, nil
  53. }
  54. func (fs *FilerServer) jwt(fileId string) security.EncodedJwt {
  55. return security.GenJwt(fs.secret, fileId)
  56. }