httpfsclient

package module
v0.0.0-...-22c6f36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2019 License: MIT Imports: 14 Imported by: 0

README

httpfsclient

httpfs client.

Example:

const redisAddr = "localhost:6379"
const clusterId = "static"

func init() {
	httpfsclient.InitClusters(redisAddr, "", "0", clusterId)
}

func WriteAndRead(file string) {
	buff, _ := os.Open(file)
	defer buff.Close()
	//write file to cluster
	link, _ := httpfsclient.Write(buff, clusterId, file, CollectionTxt)
	fmt.Println(link.Url())
	//read file
	bs, _ := link.Read()
	fmt.Println(string(bs))
	// crop and resize image
	links, err := link.ImageResize([]int{10, 10, 100, 100}, [][]int{{60, 60}})
}


Dependency

github.com/mozillazg/request
github.com/gomodule/redigo/redis

Documentation

Index

Constants

View Source
const (
	CollectionImage  = "image"
	CollectionVideo  = "video"
	CollectionEpub   = "epub"
	CollectionTxt    = "txt"
	CollectionPdf    = "pdf"
	CollectionBin    = "bin"
	CollectionOffice = "office"
	CollectionZip    = "zip"
)
View Source
const (
	FileStateNotStart  = 0
	FileStateUploading = 1
	FileStateOk        = 2
	FileStateFail      = 3
)
View Source
const (
	StateOk    = 0
	StateError = 1
)

Variables

This section is empty.

Functions

func InitClusters

func InitClusters(url string, clusterIds ...string)
func IsHfLink(url string) bool

func ParseResult

func ParseResult(bs []byte, result interface{}) error

Types

type Client

type Client struct {
	Server string
}

func (*Client) Call

func (c *Client) Call(module, method string, args interface{}, result interface{}) error

func (*Client) ImageCropResize

func (c *Client) ImageCropResize(filePath string, crop []int, sizes [][]int) (result []string, err error)

func (*Client) Ls

func (c *Client) Ls(filePath string) ([]FileInfo, error)

func (*Client) Read

func (c *Client) Read(filePath string) ([]byte, error)

func (*Client) Stat

func (c *Client) Stat(filePath string) (FileInfo, error)

type Cluster

type Cluster struct {
	Id string
	// contains filtered or unexported fields
}

func (Cluster) ChooseServer

func (c Cluster) ChooseServer() Server

func (Cluster) GetServer

func (c Cluster) GetServer(serverId string) Server

func (Cluster) HfsId

func (c Cluster) HfsId(url string) (clusterId, serverId string)

func (Cluster) Url

func (c Cluster) Url(serverId string) string

type Clusters

type Clusters struct {
	// contains filtered or unexported fields
}

Clusters include many clusters

func GetClusters

func GetClusters() *Clusters

func (*Clusters) GetCluster

func (c *Clusters) GetCluster(clusterId string) (*Cluster, bool)

func (*Clusters) GetServer

func (c *Clusters) GetServer(clusterId, serverId string) Server

func (*Clusters) HfsId

func (c *Clusters) HfsId(url string) (clusterId, serverId string)

func (*Clusters) Url

func (c *Clusters) Url(clusterId, serverId string) string

type File

type File struct {
	Id         int
	ServerId   int
	Path       string
	Bytes      int64
	State      int
	CreateTime int64
	Mime       sql.NullString
	RawName    sql.NullString
	Backup1    sql.NullInt64
	Backup2    sql.NullInt64
}

type FileInfo

type FileInfo struct {
	Name     string
	Size     int64
	Mode     os.FileMode
	ModeTime time.Time
	IsDir    bool
	RawName  string
}
type HfLink string

HfLink := clusterId:serverId/relativePath

func FromUrl

func FromUrl(url string) (HfLink, bool)

http://xxx/image/1.jpg -> s:1/image/1.jpg

func NewHfLink(clusterId, serverId, filepath string) HfLink

func Write

func Write(reader io.Reader, clusterId, fileName, collection string) (HfLink, error)

func WriteServer

func WriteServer(server Server, reader io.Reader, fileName, collection string) (HfLink, error)

func (HfLink) Call

func (d HfLink) Call(module, method string, args, result interface{}) error

func (HfLink) CallAsync

func (d HfLink) CallAsync(module, method string, args interface{}) error

func (HfLink) ImageResize

func (d HfLink) ImageResize(crop []int, sizes [][]int) ([]HfLink, error)

func (HfLink) Mp4

func (d HfLink) Mp4(videoId int, redisProgressKey string) error

func (HfLink) Parts

func (d HfLink) Parts() (string, string, string)

func (HfLink) Path

func (d HfLink) Path() string

func (HfLink) Read

func (d HfLink) Read() ([]byte, error)

func (HfLink) Stat

func (d HfLink) Stat() (FileInfo, error)

func (HfLink) String

func (d HfLink) String() string

func (HfLink) Url

func (d HfLink) Url() string

eg. s:1/txt/00/00/yyfoatapk5/bdu9kjosiq.go -> http://xxx/txt/00/00/yyfoatapk5/bdu9kjosiq.go

func (HfLink) VideoCompressDash

func (d HfLink) VideoCompressDash(videoId int, redisProgressKey string) error

type ImageTransformParam

type ImageTransformParam struct {
	FilePath string
	Crop     []int
	Resize   [][]int
}

type JsonResult

type JsonResult struct {
	State int
	Data  interface{}
	Err   error
}

func (*JsonResult) Error

func (r *JsonResult) Error() string

type Methods

type Methods struct {
}

func (Methods) Call

func (c Methods) Call(clusterId, serverId, module, method string, args interface{}, result interface{}) error

func (Methods) CallAsync

func (c Methods) CallAsync(clusterId, serverId, module, method string, args interface{}) error

func (Methods) ImageCropResize

func (m Methods) ImageCropResize(hf HfLink, crop []int, sizes [][]int) ([]HfLink, error)

func (Methods) Mp4

func (m Methods) Mp4(hf HfLink, videoId int, progressKey string) error

func (Methods) VideoCompressDash

func (m Methods) VideoCompressDash(hf HfLink, videoId int, progressKey string) error
type NullHfLink struct{ sql.NullString }
func FromHfLink(s HfLink) NullHfLink
func NewNullHfLink(s HfLink, valid bool) NullHfLink

NewString creates a new String

func (s NullHfLink) HfLink() HfLink

func (NullHfLink) IsZero

func (s NullHfLink) IsZero() bool

IsZero returns true for null strings, for potential future omitempty support.

func (NullHfLink) MarshalJSON

func (s NullHfLink) MarshalJSON() ([]byte, error)

MarshalJSON implements json.Marshaler. It will encode null if this String is null.

func (NullHfLink) MarshalText

func (s NullHfLink) MarshalText() ([]byte, error)

MarshalText implements encoding.TextMarshaler. It will encode a blank string when this String is null.

func (NullHfLink) Ptr

func (s NullHfLink) Ptr() *string

Ptr returns a pointer to this String's value, or a nil pointer if this String is null.

func (*NullHfLink) SetValid

func (s *NullHfLink) SetValid(v string)

SetValid changes this String's value and also sets it to be non-null.

func (*NullHfLink) UnmarshalJSON

func (s *NullHfLink) UnmarshalJSON(data []byte) error

func (*NullHfLink) UnmarshalText

func (s *NullHfLink) UnmarshalText(text []byte) error

UnmarshalText implements encoding.TextUnmarshaler. It will unmarshal to a null String if the input is a blank string.

func (NullHfLink) Url

func (s NullHfLink) Url() string

type RedisService

type RedisService interface {
	HMGetAll(key string, result interface{}) error
}

type Server

type Server struct {
	ClusterId, ServerId string
	Local, Proxy        string
	Ut                  int64 //update time
	RatedSpace          int   //MB
	FreeSpace           int   //MB
	Cpu                 int   //
	Mem                 int   //MB
	MemFree             int
	LoadAverage         int
	// contains filtered or unexported fields
}

func GetServer

func GetServer(clusterId, serverId string) Server

func (Server) Id

func (s Server) Id() string

type ServerUt

type ServerUt struct {
	Ut          int64
	UpdateCount int
}

type VideoCompressParam

type VideoCompressParam struct {
	File             string
	ProgressRedisKey string
	VideoId          int
}

type Writer

type Writer struct {
	ClusterId, ServerId string
}

func (*Writer) Write

func (w *Writer) Write(reader io.Reader, fileName, collection string) (HfLink, error)

Directories

Path Synopsis
util

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL