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
1.8 KiB

11 years ago
7 years ago
7 years ago
7 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/seaweedfs/weed/filer2"
  6. _ "github.com/chrislusf/seaweedfs/weed/filer2/cassandra"
  7. _ "github.com/chrislusf/seaweedfs/weed/filer2/leveldb"
  8. _ "github.com/chrislusf/seaweedfs/weed/filer2/memdb"
  9. _ "github.com/chrislusf/seaweedfs/weed/filer2/mysql"
  10. _ "github.com/chrislusf/seaweedfs/weed/filer2/postgres"
  11. _ "github.com/chrislusf/seaweedfs/weed/filer2/redis"
  12. "github.com/chrislusf/seaweedfs/weed/security"
  13. "github.com/chrislusf/seaweedfs/weed/glog"
  14. )
  15. type FilerServer struct {
  16. port string
  17. masters []string
  18. collection string
  19. defaultReplication string
  20. redirectOnRead bool
  21. disableDirListing bool
  22. secret security.Secret
  23. filer *filer2.Filer
  24. maxMB int
  25. }
  26. func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, ip string, port int, masters []string, collection string,
  27. replication string, redirectOnRead bool, disableDirListing bool,
  28. maxMB int,
  29. secret string,
  30. ) (fs *FilerServer, err error) {
  31. fs = &FilerServer{
  32. masters: masters,
  33. collection: collection,
  34. defaultReplication: replication,
  35. redirectOnRead: redirectOnRead,
  36. disableDirListing: disableDirListing,
  37. maxMB: maxMB,
  38. port: ip + ":" + strconv.Itoa(port),
  39. }
  40. if len(masters) == 0 {
  41. glog.Fatal("master list is required!")
  42. }
  43. fs.filer = filer2.NewFiler(masters)
  44. go fs.filer.KeepConnectedToMaster()
  45. fs.filer.LoadConfiguration()
  46. defaultMux.HandleFunc("/favicon.ico", faviconHandler)
  47. defaultMux.HandleFunc("/", fs.filerHandler)
  48. if defaultMux != readonlyMux {
  49. readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
  50. }
  51. return fs, nil
  52. }
  53. func (fs *FilerServer) jwt(fileId string) security.EncodedJwt {
  54. return security.GenJwt(fs.secret, fileId)
  55. }