opensdk

package module
v0.0.0-...-d41ede4 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2023 License: MIT Imports: 10 Imported by: 0

README

openSDK 文件存储开放SDK

实现了对文件存储服务的开放接口封装, 可实现文件的存取和管理.

基本信息

服务鉴权
所属程序 账号密码 密码 描述
namenode OPENAPI 可以调用开放的api接口, opensdk使用
方法列表
Description Method
IsDir IsDir(src string) bool
IsFile IsFile(src string) bool
IsExist IsExist(src string) bool
GetFileSize GetFileSize(src string) int64
GetNode GetNode(src string) *TNode
GetDirNameList GetDirNameList(src string, limit, offset int) (*DirNameListDto, int)
GetDirNodeList GetDirNodeList(src string, limit, offset int) (*DirNodeListDto, int)
DoMkDir DoMkDir(path string) error
DoDelete DoDelete(src string) error
DoRename DoRename(src string, dst string) error
DoCopy DoCopy(src, dst string) error
DoMove DoMove(src, dst string) error
DoQueryToken DoQueryToken(token string) (*StreamToken, error)
DoAskReadToken DoAskReadToken(src string) (*StreamToken, error)
DoAskWriteToken DoAskWriteToken(src string) (*StreamToken, error)
DoRefreshToken DoRefreshToken(token string) (*StreamToken, error)
DoSubmitWriteToken DoSubmitWriteToken(token string, override bool) (node *TNode, err error)
SetNodeStreamAddr SetNodeStreamAddr(nodes map[string]string)
DoWriteToken DoWriteToken(nodeNo, token string, pieceNumber int, sha256 string, reader io.Reader) (err error)
sdk暂时仅支持golang语言. 可以单独拷贝到其他项目使用. example目录下包含一些调用示例供参考使用.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrorAuthentication = errors.New("authentication failed")

Functions

func FileUploader

func FileUploader(path string, token *StreamToken, pieceSize int64, doWriteToken doWriteTokenFunc) error

FileUploader FileUploader

func TokenWriter

func TokenWriter(reader io.Reader, token *StreamToken, pieceSize int64, doWriteToken doWriteTokenFunc) (err error)

TokenWriter TokenWriter

Types

type Conn4RPC

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

Conn4RPC Conn4RPC

func (*Conn4RPC) DoLogin

func (c *Conn4RPC) DoLogin() error

DoLogin 登录一下, 获取 Data={"AccessKey":"e194244b-1683-cb4c-98a9-a79e43fe1576","SecretKey":"e194244b-1683-cb4c-98a9-a05f6ef420d2"}

func (*Conn4RPC) DoRPC

func (c *Conn4RPC) DoRPC(method string, args interface{}, reply interface{}) (err error)

DoRPC RPC

func (*Conn4RPC) GetAccessKey

func (c *Conn4RPC) GetAccessKey() (string, error)

GetAccessKey 获取accessKey, 为空则自动登录一下

func (*Conn4RPC) GetClient

func (c *Conn4RPC) GetClient() (IRPCClient, error)

GetClient 获取一个空闲的客户端

func (*Conn4RPC) GetSecretKey

func (c *Conn4RPC) GetSecretKey() (string, error)

GetSecretKey 获取 secretKey

func (*Conn4RPC) GetUser

func (c *Conn4RPC) GetUser() string

GetUser 获取用户ID

type CopyNodeBo

type CopyNodeBo struct {
	SRC      string
	DST      string
	Override bool
}

CopyNodeBo 拷贝

type CreateUserBo

type CreateUserBo struct {
	UserType int
	UserID   string
	UserName string
	UserPWD  string
}

CreateUserBo 用户表存储的结构

type DataStream

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

DataStream DataStream

func NewDataStream

func NewDataStream() *DataStream

NewDataStream NewDataStream

func (*DataStream) DoReadToken

func (s *DataStream) DoReadToken(nodeNo, token, endpoint string, offset int64) (r io.ReadCloser, err error)

DoReadToken /stream/read/tokenxxxx

func (*DataStream) DoWriteToken

func (s *DataStream) DoWriteToken(nodeNo, token, endpoint string, pieceNumber int, sha256 string, reader io.Reader) (err error)

DoWriteToken /stream/put/tokenxxxx

func (*DataStream) GetNodeStreamAddr

func (s *DataStream) GetNodeStreamAddr(nodeNo string, endpoint string) (string, error)

GetNodeStreamAddr 获取nodeNo的地址映射

func (*DataStream) GetReadStreamURL

func (s *DataStream) GetReadStreamURL(nodeNo, token, endpoint string) (string, error)

GetReadStreamURL 获取下载url

func (*DataStream) GetWriteStreamURL

func (s *DataStream) GetWriteStreamURL(nodeNo, token, endpoint string) (string, error)

GetWriteStreamURL 获取上传url

func (*DataStream) SetNodeStreamAddr

func (s *DataStream) SetNodeStreamAddr(nodes map[string]string)

SetNodeStreamAddr 设置nodeNo的地址映射

type DirNameListDto

type DirNameListDto struct {
	Datas []string
	Total int
}

DirNameListDto 文件夹目录列表

type DirNodeListDto

type DirNodeListDto struct {
	Datas []TNode
	Total int
}

DirNodeListDto 文件夹目录列表

type IConn4RPC

type IConn4RPC interface {
	GetAccessKey() (string, error)
	GetClient() (IRPCClient, error)
	DoRPC(method string, args interface{}, reply interface{}) error
}

IConn4RPC RPC连接会话

func NewConn4RPC

func NewConn4RPC(addr string, user User) IConn4RPC

NewConn4RPC RPC客户端

type IOpenApi

type IOpenApi interface {
	ConnTest(user User) error

	IsDir(src string) (bool, error)
	IsFile(src string) (bool, error)
	IsExist(src string) (bool, error)
	GetFileSize(src string) (int64, error)

	GetNode(src string) (*TNode, error)
	GetNodes(src []string) ([]TNode, error)
	GetDirNameList(src string, limit, offset int) (*DirNameListDto, error)
	GetDirNodeList(src string, limit, offset int) (*DirNodeListDto, error)

	DoMkDir(path string) (string, error)
	DoDelete(src string) error
	DoRename(src string, dst string) error
	DoCopy(src, dst string, override bool) (string, error)
	DoMove(src, dst string, override bool) error

	DoQueryToken(token string) (*StreamToken, error)
	DoAskReadToken(src string) (*StreamToken, error)
	DoAskWriteToken(src string) (*StreamToken, error)
	DoRefreshToken(token string) (*StreamToken, error)
	DoSubmitWriteToken(token string, override bool) (*TNode, error)
	SetDataNodeDNS(nodes map[string]string)
	GetReadStreamURL(nodeNo, token, endpoint string) (string, error)
	GetWriteStreamURL(nodeNo, token, endpoint string) (string, error)
	DoWriteToken(nodeNo, token, endpoint string, pieceNumber int, sha256 string, reader io.Reader) error
	DoReadToken(nodeNo, token, endpoint string, offset int64) (io.ReadCloser, error)
}

IOpenApi 开放api

func NewOpenApi

func NewOpenApi(addr string, user User) IOpenApi

NewOpenApi NewOpenApi

type IRPCClient

type IRPCClient interface {
	Close() error
	Call(serviceMethod string, args interface{}, reply interface{}) error
}

IRPCClient RPC发起接口

type IServerMG

type IServerMG interface {
	ConnTest(user User) error
	DoCreateUser(user CreateUserBo) (bool, error)
	DoUpdatePWD(user, pwd string) (bool, error)
	DoDeleteUser(userID string) (bool, error)
	DoListAllUsers() (*UserListDto, error)
}

IServerMG 管理类接口

func NewSvrMngApi

func NewSvrMngApi(addr string, user User) IServerMG

NewSvrMngApi 服务器管理接口, 如: 用户管理

type LimitQueryBo

type LimitQueryBo struct {
	Query  string
	Limit  int
	Offset int
}

LimitQueryBo 分页查询

type LimitedReader

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

func NewLimitedReader

func NewLimitedReader(r io.Reader, n int64) *LimitedReader

NewLimitedReader NewLimitedReader

func (*LimitedReader) Next

func (l *LimitedReader) Next() (bool, error)

func (*LimitedReader) Read

func (l *LimitedReader) Read(p []byte) (n int, err error)

type MoveNodeBo

type MoveNodeBo struct {
	SRC      string
	DST      string
	Override bool
}

MoveNodeBo 移动

type OpenSdkImpl

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

OpenSdkImpl 开放api接口

func (*OpenSdkImpl) ConnTest

func (s *OpenSdkImpl) ConnTest(user User) error

ConnTest ConnTest

func (*OpenSdkImpl) DoAskReadToken

func (s *OpenSdkImpl) DoAskReadToken(src string) (*StreamToken, error)

func (*OpenSdkImpl) DoAskWriteToken

func (s *OpenSdkImpl) DoAskWriteToken(src string) (*StreamToken, error)

func (*OpenSdkImpl) DoCopy

func (s *OpenSdkImpl) DoCopy(src, dst string, override bool) (string, error)

func (*OpenSdkImpl) DoDelete

func (s *OpenSdkImpl) DoDelete(src string) error

func (*OpenSdkImpl) DoMkDir

func (s *OpenSdkImpl) DoMkDir(path string) (string, error)

func (*OpenSdkImpl) DoMove

func (s *OpenSdkImpl) DoMove(src, dst string, override bool) error

func (*OpenSdkImpl) DoQueryToken

func (s *OpenSdkImpl) DoQueryToken(token string) (*StreamToken, error)

func (*OpenSdkImpl) DoReadToken

func (s *OpenSdkImpl) DoReadToken(nodeNo, token, endpoint string, offset int64) (io.ReadCloser, error)

func (*OpenSdkImpl) DoRefreshToken

func (s *OpenSdkImpl) DoRefreshToken(token string) (*StreamToken, error)

func (*OpenSdkImpl) DoRename

func (s *OpenSdkImpl) DoRename(src string, dst string) error

func (*OpenSdkImpl) DoSubmitWriteToken

func (s *OpenSdkImpl) DoSubmitWriteToken(token string, override bool) (node *TNode, err error)

func (*OpenSdkImpl) DoWriteToken

func (s *OpenSdkImpl) DoWriteToken(nodeNo, token, endpoint string, pieceNumber int, sha256 string, reader io.Reader) (err error)

func (*OpenSdkImpl) GetDirNameList

func (s *OpenSdkImpl) GetDirNameList(src string, limit, offset int) (*DirNameListDto, error)

func (*OpenSdkImpl) GetDirNodeList

func (s *OpenSdkImpl) GetDirNodeList(src string, limit, offset int) (*DirNodeListDto, error)

func (*OpenSdkImpl) GetFileSize

func (s *OpenSdkImpl) GetFileSize(src string) (int64, error)

func (*OpenSdkImpl) GetNode

func (s *OpenSdkImpl) GetNode(src string) (*TNode, error)

func (*OpenSdkImpl) GetNodes

func (s *OpenSdkImpl) GetNodes(src []string) ([]TNode, error)

func (*OpenSdkImpl) GetReadStreamURL

func (s *OpenSdkImpl) GetReadStreamURL(nodeNo, token, endpoint string) (string, error)

func (*OpenSdkImpl) GetWriteStreamURL

func (s *OpenSdkImpl) GetWriteStreamURL(nodeNo, token, endpoint string) (string, error)

func (*OpenSdkImpl) IsDir

func (s *OpenSdkImpl) IsDir(src string) (bool, error)

func (*OpenSdkImpl) IsExist

func (s *OpenSdkImpl) IsExist(src string) (bool, error)

func (*OpenSdkImpl) IsFile

func (s *OpenSdkImpl) IsFile(src string) (bool, error)

func (*OpenSdkImpl) SetDataNodeDNS

func (s *OpenSdkImpl) SetDataNodeDNS(nodes map[string]string)

type PwdUpdateBo

type PwdUpdateBo struct {
	User string
	Pwd  string
}

PwdUpdateBo 更改用户密码

type RPCClient

type RPCClient struct {
	ClientID string

	*rpc.Client
	// contains filtered or unexported fields
}

RPCClient RPCClient

func (*RPCClient) Call

func (client *RPCClient) Call(serviceMethod string, args interface{}, reply interface{}) error

Call override Call

func (*RPCClient) Close

func (client *RPCClient) Close() error

Close override Close

type RequestBody

type RequestBody struct {
	AccessKey   string
	Signature   string
	RequestBody interface{}
}

RequestBody RPC请求体

type ServerMgSdkImpl

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

ServerMgSdkImpl 开发api接口

func (*ServerMgSdkImpl) ConnTest

func (s *ServerMgSdkImpl) ConnTest(user User) error

ConnTest ConnTest

func (*ServerMgSdkImpl) DoCreateUser

func (s *ServerMgSdkImpl) DoCreateUser(user CreateUserBo) (bool, error)

func (*ServerMgSdkImpl) DoDeleteUser

func (s *ServerMgSdkImpl) DoDeleteUser(userID string) (bool, error)

func (*ServerMgSdkImpl) DoListAllUsers

func (s *ServerMgSdkImpl) DoListAllUsers() (*UserListDto, error)

func (*ServerMgSdkImpl) DoUpdatePWD

func (s *ServerMgSdkImpl) DoUpdatePWD(user, pwd string) (bool, error)

type Session

type Session struct {
	AccessKey string
	SecretKey string
}

Session 授权信息

type SrcAndDstBo

type SrcAndDstBo struct {
	SRC string
	DST string
}

SrcAndDstBo src 和 dst

type StreamToken

type StreamToken struct {
	Token    string
	NodeNo   string
	FileID   string
	FilePath string
	FileSize int64
	CTime    int64
	MTime    int64
	EndPoint string
	Type     StreamTokenType
}

StreamToken 流操作Token

func (*StreamToken) Clone

func (ua *StreamToken) Clone(val interface{}) error

Clone Clone

type StreamTokenType

type StreamTokenType int

StreamTokenType token类型

type TNode

type TNode struct {
	Id    string
	Pid   string
	Addr  string
	Flag  int
	Name  string
	Size  int64
	Ctime int64
	Mtime int64
	Props string
}

TNode 元数据内容(filenames)

type User

type User struct {
	User     string
	Passwd   string
	PropJSON string
}

User 登录凭据

type UserInfo

type UserInfo struct {
	UserType int
	UserID   string
	UserName string
	CtTime   time.Time
}

UserInfo 用户表存储的结构

type UserListDto

type UserListDto struct {
	Datas []UserInfo
	Total int
}

UserListDto 用户信息列表

type WriteTokenBo

type WriteTokenBo struct {
	Token    string
	Override bool
}

WriteTokenBo 文件上传递交token

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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