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.

60 lines
1.5 KiB

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