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.

59 lines
1.5 KiB

7 years ago
7 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/security"
  12. "github.com/chrislusf/seaweedfs/weed/glog"
  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. }
  24. type FilerServer struct {
  25. option *FilerOption
  26. secret security.Secret
  27. filer *filer2.Filer
  28. }
  29. func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, option *FilerOption) (fs *FilerServer, err error) {
  30. fs = &FilerServer{
  31. option: option,
  32. }
  33. if len(option.Masters) == 0 {
  34. glog.Fatal("master list is required!")
  35. }
  36. fs.filer = filer2.NewFiler(option.Masters)
  37. go fs.filer.KeepConnectedToMaster()
  38. fs.filer.LoadConfiguration()
  39. defaultMux.HandleFunc("/favicon.ico", faviconHandler)
  40. defaultMux.HandleFunc("/", fs.filerHandler)
  41. if defaultMux != readonlyMux {
  42. readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
  43. }
  44. return fs, nil
  45. }
  46. func (fs *FilerServer) jwt(fileId string) security.EncodedJwt {
  47. return security.GenJwt(fs.secret, fileId)
  48. }