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.

69 lines
1.8 KiB

6 years ago
7 years ago
7 years ago
6 years ago
7 years ago
10 years ago
  1. package weed_server
  2. import (
  3. "net/http"
  4. "github.com/chrislusf/seaweedfs/weed/filer2"
  5. _ "github.com/chrislusf/seaweedfs/weed/filer2/cassandra"
  6. _ "github.com/chrislusf/seaweedfs/weed/filer2/leveldb"
  7. _ "github.com/chrislusf/seaweedfs/weed/filer2/memdb"
  8. _ "github.com/chrislusf/seaweedfs/weed/filer2/mysql"
  9. _ "github.com/chrislusf/seaweedfs/weed/filer2/postgres"
  10. _ "github.com/chrislusf/seaweedfs/weed/filer2/redis"
  11. "github.com/chrislusf/seaweedfs/weed/glog"
  12. "github.com/chrislusf/seaweedfs/weed/msgqueue"
  13. _ "github.com/chrislusf/seaweedfs/weed/msgqueue/kafka"
  14. _ "github.com/chrislusf/seaweedfs/weed/msgqueue/log"
  15. "github.com/chrislusf/seaweedfs/weed/security"
  16. )
  17. type FilerOption struct {
  18. Masters []string
  19. Collection string
  20. DefaultReplication string
  21. RedirectOnRead bool
  22. DisableDirListing bool
  23. MaxMB int
  24. SecretKey string
  25. DirListingLimit int
  26. DataCenter string
  27. EnableNotification bool
  28. }
  29. type FilerServer struct {
  30. option *FilerOption
  31. secret security.Secret
  32. filer *filer2.Filer
  33. }
  34. func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption) (fs *FilerServer, err error) {
  35. fs = &FilerServer{
  36. option: option,
  37. }
  38. if len(option.Masters) == 0 {
  39. glog.Fatal("master list is required!")
  40. }
  41. fs.filer = filer2.NewFiler(option.Masters)
  42. go fs.filer.KeepConnectedToMaster()
  43. fs.filer.LoadConfiguration()
  44. if fs.option.EnableNotification {
  45. msgqueue.LoadConfiguration()
  46. }
  47. defaultMux.HandleFunc("/favicon.ico", faviconHandler)
  48. defaultMux.HandleFunc("/", fs.filerHandler)
  49. if defaultMux != readonlyMux {
  50. readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
  51. }
  52. return fs, nil
  53. }
  54. func (fs *FilerServer) jwt(fileId string) security.EncodedJwt {
  55. return security.GenJwt(fs.secret, fileId)
  56. }