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.

40 lines
952 B

5 years ago
  1. package filesys
  2. import (
  3. "fmt"
  4. "strings"
  5. "google.golang.org/grpc"
  6. "github.com/chrislusf/seaweedfs/weed/pb"
  7. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  8. )
  9. var _ = filer_pb.FilerClient(&WFS{})
  10. func (wfs *WFS) WithFilerClient(fn func(filer_pb.SeaweedFilerClient) error) error {
  11. err := pb.WithCachedGrpcClient(func(grpcConnection *grpc.ClientConn) error {
  12. client := filer_pb.NewSeaweedFilerClient(grpcConnection)
  13. return fn(client)
  14. }, wfs.option.FilerGrpcAddress, wfs.option.GrpcDialOption)
  15. if err == nil {
  16. return nil
  17. }
  18. return err
  19. }
  20. func (wfs *WFS) AdjustedUrl(hostAndPort string) string {
  21. if !wfs.option.OutsideContainerClusterMode {
  22. return hostAndPort
  23. }
  24. commaIndex := strings.Index(hostAndPort, ":")
  25. if commaIndex < 0 {
  26. return hostAndPort
  27. }
  28. filerCommaIndex := strings.Index(wfs.option.FilerGrpcAddress, ":")
  29. return fmt.Sprintf("%s:%s", wfs.option.FilerGrpcAddress[:filerCommaIndex], hostAndPort[commaIndex+1:])
  30. }