Documentation
¶
Index ¶
- Constants
- Variables
- func ChiperToInt(c string) int32
- func ChiperToString(i int32) string
- func EncryptionIValid(i int32) bool
- func FileUploader(path string, proxyWriter func(io.Writer) io.Writer, ...) (r *io.PipeReader, contentType string, size int64)
- func IsValidCipher(c string) bool
- type Attribute
- type Authorization
- type AuthorizationType
- type BulkPublishResponse
- type ContentType
- type CountResponse
- type CredentialsRequest
- type Endpoint
- type FileAttributes
- type FileChanges
- type FileListRequest
- type FileListResponse
- type FileRequest
- type FileResponseItem
- type FileUpdateItem
- type LibDM
- func (libdm LibDM) CreateNamespace(name string, customNS bool) (*StringResponse, error)
- func (libdm LibDM) DeleteAttribute(attribute Attribute, namespace, name string) (*RestRequestResponse, error)
- func (libdm LibDM) DeleteFile(name string, id uint, all bool, attributes FileAttributes) (*CountResponse, error)
- func (libdm LibDM) DeleteNamespace(name string) (*StringResponse, error)
- func (libdm LibDM) DownloadFile(name string, id uint, namespace, localFilePath string, appendFilename ...bool) error
- func (libdm LibDM) GetFile(name string, id uint, namespace string) (*http.Response, string, error)
- func (libdm LibDM) GetNamespaces() (*StringSliceResponse, error)
- func (libdm LibDM) ListFiles(name string, id uint, allNamespaces bool, attributes FileAttributes, ...) (*FileListResponse, error)
- func (libdm LibDM) Login(username, password string) (*LoginResponse, error)
- func (libdm LibDM) PublishFile(name string, id uint, publicName string, all bool, attributes FileAttributes) (interface{}, error)
- func (libdm LibDM) Register(username, password string) (*RestRequestResponse, error)
- func (libdm LibDM) Request(ep Endpoint, payload, response interface{}, authorized bool) (*RestRequestResponse, error)
- func (libdm LibDM) UpdateAttribute(attribute Attribute, namespace, name, newName string) (*RestRequestResponse, error)
- func (libdm LibDM) UpdateFile(name string, id uint, namespace string, all bool, changes FileChanges) (*CountResponse, error)
- func (libdm LibDM) UpdateNamespace(name, newName string, customNS bool) (*StringResponse, error)
- func (libdm LibDM) UploadFile(localFile, name string, public bool, replaceFile uint, ...) (*UploadResponse, error)
- type LoginResponse
- type Method
- type NamespaceRequest
- type NamespaceType
- type OptionalRequetsParameter
- type PingRequest
- type PublishResponse
- type Request
- func (request *Request) BuildClient() *http.Client
- func (request Request) Do(retVar interface{}) (*RestRequestResponse, error)
- func (request *Request) DoHTTPRequest() (*http.Response, error)
- func (request *Request) WithAuth(a Authorization) *Request
- func (request *Request) WithAuthFromConfig() *Request
- func (request *Request) WithBenchCallback(c chan time.Time) *Request
- func (request *Request) WithContentType(ct ContentType) *Request
- func (request *Request) WithHeader(name string, value string) *Request
- func (request *Request) WithMethod(m Method) *Request
- func (request *Request) WithRequestType(rType RequestType) *Request
- type RequestConfig
- type RequestType
- type ResponseErr
- type ResponseStatus
- type RestRequestResponse
- type StringResponse
- type StringSliceResponse
- type UpdateAttributeRequest
- type UploadRequest
- type UploadResponse
- type UploadType
Constants ¶
const ( // Ping EPPing Endpoint = "/ping" // User EPUser Endpoint = "/user" EPLogin Endpoint = EPUser + "/login" EPRegister Endpoint = EPUser + "/register" // Files EPFile Endpoint = "/file" EPFileList Endpoint = EPFile + "s" EPFileUpdate Endpoint = EPFile + "/update" EPFileDelete Endpoint = EPFile + "/delete" EPFileGet Endpoint = EPFile + "/get" EPFilePublish Endpoint = EPFile + "/publish" // Upload EPFileUpload Endpoint = "/upload" + EPFile // Attributes EPAttribute Endpoint = "/attribute" // Tags EPAttributeTag = EPAttribute + "/tag" EPTagUpdate = EPAttributeTag + "/update" EPTagDelete = EPAttributeTag + "/delete" // Group EPAttributeGroup = EPAttribute + "/group" EPGroupUpdate = EPAttributeGroup + "/update" EPGroupDelete = EPAttributeGroup + "/delete" // Namespace EPNamespace Endpoint = "/namespace" EPNamespaceCreate = EPNamespace + "/create" EPNamespaceUpdate = EPNamespace + "/update" EPNamespaceDelete = EPNamespace + "/delete" EPNamespaceList = EPNamespace + "s" )
Remote endpoints
const ( // HeaderStatus headername for status in response HeaderStatus string = "X-Response-Status" // HeaderStatusMessage headername for status in response HeaderStatusMessage string = "X-Response-Message" // HeaderContentType contenttype of response HeaderContentType string = "Content-Type" // HeaderFileName filename header HeaderFileName string = "X-Filename" // HeaderRequest request content HeaderRequest string = "Request" // HeaderEncryption encryption header HeaderEncryption string = "X-Encryption" // HeaderContentLength request content length HeaderContentLength string = "ContentLength" )
Variables ¶
var ( // ErrInvalidResponseHeaders error on missing or malformed response headers ErrInvalidResponseHeaders = errors.New("Invalid response headers") // ErrResponseError response returned an error ErrResponseError = errors.New("response returned an error") // ErrResponseFilenameInvalid if server returns no filename ErrResponseFilenameInvalid = errors.New("invalid filename received") )
var Boundary = "MachliJalKiRaniHaiJeevanUskaPaaniHai"
var EncryptionCiphers = []string{
"aes",
}
EncryptionCiphers supported encryption chipers
var NoProxyWriter = func(w io.Writer) io.Writer {
return w
}
NopNoProxyWriter use to fill proxyWriter arg in UpdloadFile
Functions ¶
func EncryptionIValid ¶
EncryptionIValid return true if encryption i is valid
func FileUploader ¶
func IsValidCipher ¶
IsValidCipher return true if given cipher is valid
Types ¶
type Authorization ¶
type Authorization struct {
Type AuthorizationType
Palyoad string
}
Authorization the authorization params for a server request
type AuthorizationType ¶
type AuthorizationType string
AuthorizationType authorization type
const ( Bearer AuthorizationType = "Bearer" Basic AuthorizationType = "Basic" )
Authorizanion types
type BulkPublishResponse ¶
type BulkPublishResponse struct {
Files []UploadResponse `json:"files"`
}
BulkPublishResponse response for publishing a file
type ContentType ¶
type ContentType string
ContentType contenttype header of request
const (
JSONContentType ContentType = "application/json"
)
Content types
type CountResponse ¶
type CountResponse struct {
Count uint32 `json:"count"`
}
CountResponse response containing a count of changed items
type CredentialsRequest ¶
type CredentialsRequest struct {
MachineID string `json:"mid,omitempty"`
Username string `json:"username"`
Password string `json:"pass"`
}
CredentialsRequest request containing credentials
type FileAttributes ¶
type FileAttributes struct {
Tags []string `json:"tags,omitempty"`
Groups []string `json:"groups,omitempty"`
Namespace string `json:"ns"`
}
FileAttributes attributes for a file
type FileChanges ¶
type FileListRequest ¶
type FileListRequest struct {
FileID uint `json:"fid"`
Name string `json:"name"`
AllNamespaces bool `json:"allns"`
OptionalParams OptionalRequetsParameter `json:"opt"`
Order string `json:"order,omitempty"`
Attributes FileAttributes `json:"attributes"`
}
FileListRequest contains file info (and a file)
type FileListResponse ¶
type FileListResponse struct {
Files []FileResponseItem
}
FileListResponse response for listing files
type FileRequest ¶
type FileRequest struct {
FileID uint `json:"fid"`
Name string `json:"name,omitempty"`
PublicName string `json:"pubname,omitempty"`
Updates FileUpdateItem `json:"updates,omitempty"`
All bool `json:"all"`
Attributes FileAttributes `json:"attributes"`
}
FileRequest contains data to update a file
type FileResponseItem ¶
type FileResponseItem struct {
ID uint `json:"id"`
Size int64 `json:"size"`
CreationDate time.Time `json:"creation"`
Name string `json:"name"`
IsPublic bool `json:"isPub"`
PublicName string `json:"pubname"`
Attributes FileAttributes `json:"attrib"`
Encryption string `json:"e"`
}
FileResponseItem file item for file response
type FileUpdateItem ¶
type FileUpdateItem struct {
IsPublic string `json:"ispublic,omitempty"`
NewName string `json:"name,omitempty"`
NewNamespace string `json:"namespace,omitempty"`
RemoveTags []string `json:"rem_tags,omitempty"`
RemoveGroups []string `json:"rem_groups,omitempty"`
AddTags []string `json:"add_tags,omitempty"`
AddGroups []string `json:"add_groups,omitempty"`
}
FileUpdateItem lists changes to a file
type LibDM ¶
type LibDM struct {
Config *RequestConfig
}
LibDM data required in all requests
func (LibDM) CreateNamespace ¶
func (libdm LibDM) CreateNamespace(name string, customNS bool) (*StringResponse, error)
CreateNamespace creates a namespace
func (LibDM) DeleteAttribute ¶
func (libdm LibDM) DeleteAttribute(attribute Attribute, namespace, name string) (*RestRequestResponse, error)
DeleteAttribute update an attribute
func (LibDM) DeleteFile ¶
func (libdm LibDM) DeleteFile(name string, id uint, all bool, attributes FileAttributes) (*CountResponse, error)
DeleteFile deletes the desired file(s)
func (LibDM) DeleteNamespace ¶
func (libdm LibDM) DeleteNamespace(name string) (*StringResponse, error)
DeleteNamespace update a namespace
func (LibDM) DownloadFile ¶
func (libdm LibDM) DownloadFile(name string, id uint, namespace, localFilePath string, appendFilename ...bool) error
DownloadFile downloads and saves a file to the given localFilePath. If the file exists, it will be overwritten
func (LibDM) GetFile ¶ added in v1.0.1
DownloadFileToReader returns a readCloser for the request body == file content Body must be closed
func (LibDM) GetNamespaces ¶
func (libdm LibDM) GetNamespaces() (*StringSliceResponse, error)
GetNamespaces get all namespaces
func (LibDM) ListFiles ¶
func (libdm LibDM) ListFiles(name string, id uint, allNamespaces bool, attributes FileAttributes, verbose uint8) (*FileListResponse, error)
ListFiles lists the files corresponding to the args
func (LibDM) Login ¶
func (libdm LibDM) Login(username, password string) (*LoginResponse, error)
Login login into the server
func (LibDM) PublishFile ¶
func (libdm LibDM) PublishFile(name string, id uint, publicName string, all bool, attributes FileAttributes) (interface{}, error)
PublishFile publishs a file. If "all" is true, the response object is BulkPublishResponse. Else it is PublishResponse
func (LibDM) Register ¶
func (libdm LibDM) Register(username, password string) (*RestRequestResponse, error)
Register create a new account. Return true on success
func (LibDM) Request ¶
func (libdm LibDM) Request(ep Endpoint, payload, response interface{}, authorized bool) (*RestRequestResponse, error)
Request do a request using libdm
func (LibDM) UpdateAttribute ¶
func (libdm LibDM) UpdateAttribute(attribute Attribute, namespace, name, newName string) (*RestRequestResponse, error)
UpdateAttribute update an attribute
func (LibDM) UpdateFile ¶
func (libdm LibDM) UpdateFile(name string, id uint, namespace string, all bool, changes FileChanges) (*CountResponse, error)
UpdateFile updates a file on the server
func (LibDM) UpdateNamespace ¶
func (libdm LibDM) UpdateNamespace(name, newName string, customNS bool) (*StringResponse, error)
UpdateNamespace update a namespace
func (LibDM) UploadFile ¶
func (libdm LibDM) UploadFile(localFile, name string, public bool, replaceFile uint, attributes FileAttributes, proxyWriter func(w io.Writer) io.Writer, fsDetermined chan int64, strArgs ...string) (*UploadResponse, error)
UploadFile uploads the given file to the server and set's its affiliations strargs: [0] public name [1] encryption [2] encryptionKey
type LoginResponse ¶
LoginResponse response for login
type NamespaceRequest ¶
type NamespaceRequest struct {
Namespace string `json:"ns"`
NewName string `json:"newName,omitempty"`
Type NamespaceType `json:"nstype"`
}
NamespaceRequest namespace action request
type NamespaceType ¶
type NamespaceType uint8
NamespaceType type of namespace
const ( UserNamespaceType NamespaceType = iota CustomNamespaceType )
Namespace types
type OptionalRequetsParameter ¶
type OptionalRequetsParameter struct {
Verbose uint8 `json:"verb"`
}
OptionalRequetsParameter optional request parameter
type PublishResponse ¶
type PublishResponse struct {
PublicFilename string `json:"pubName"`
}
PublishResponse response for publishing a file
type Request ¶
type Request struct {
RequestType RequestType
Endpoint Endpoint
Payload interface{}
Config *RequestConfig
Method Method
ContentType ContentType
Authorization *Authorization
Headers map[string]string
BenchChan chan time.Time
}
Request a rest server request
func NewRequest ¶
func NewRequest(endpoint Endpoint, payload interface{}, config *RequestConfig) *Request
NewRequest creates a new post request
func (*Request) BuildClient ¶
BuildClient return client
func (Request) Do ¶
func (request Request) Do(retVar interface{}) (*RestRequestResponse, error)
Do a better request method
func (*Request) DoHTTPRequest ¶
DoHTTPRequest do plain http request
func (*Request) WithAuth ¶
func (request *Request) WithAuth(a Authorization) *Request
WithAuth with authorization
func (*Request) WithAuthFromConfig ¶
WithAuthFromConfig with authorization
func (*Request) WithBenchCallback ¶
WithBenchCallback with bench
func (*Request) WithContentType ¶
func (request *Request) WithContentType(ct ContentType) *Request
WithContentType with contenttype
func (*Request) WithHeader ¶
WithHeader add header to request
func (*Request) WithMethod ¶
WithMethod use a different method
func (*Request) WithRequestType ¶
func (request *Request) WithRequestType(rType RequestType) *Request
WithRequestType use different request type
type RequestConfig ¶
type RequestConfig struct {
IgnoreCert bool
URL string
MachineID string
Username string
SessionToken string
}
RequestConfig configurations for requests
func (RequestConfig) GetBearerAuth ¶
func (rc RequestConfig) GetBearerAuth() Authorization
type RequestType ¶
type RequestType uint8
RequestType type of request
const ( JSONRequestType RequestType = iota RawRequestType )
Request types
type ResponseErr ¶
type ResponseErr struct {
Response *RestRequestResponse
Err error
}
ResponseErr response error
func NewErrorFromResponse ¶
func NewErrorFromResponse(r *RestRequestResponse, err ...error) *ResponseErr
NewErrorFromResponse return error from response
func (*ResponseErr) Error ¶
func (reserr *ResponseErr) Error() string
type ResponseStatus ¶
type ResponseStatus uint8
ResponseStatus the status of response
const ( // ResponseError if there was an error ResponseError ResponseStatus = 0 // ResponseSuccess if the response is successful ResponseSuccess ResponseStatus = 1 )
type RestRequestResponse ¶
type RestRequestResponse struct {
HTTPCode int
Status ResponseStatus
Message string
Headers *http.Header
}
RestRequestResponse the response of a rest call
type StringResponse ¶
type StringResponse struct {
String string `json:"content"`
}
StringResponse response containing only one string
type StringSliceResponse ¶
type StringSliceResponse struct {
Slice []string `json:"slice"`
}
StringSliceResponse response containing only one string slice
type UpdateAttributeRequest ¶
type UpdateAttributeRequest struct {
Name string `json:"name"`
NewName string `json:"newname"`
Namespace string `json:"namespace"`
}
UpdateAttributeRequest contains data to update a tag
type UploadRequest ¶
type UploadRequest struct {
UploadType UploadType `json:"type"`
URL string `json:"url,omitempty"`
Name string `json:"name"`
Public bool `json:"pb,omitempty"`
PublicName string `json:"pbname,omitempty"`
Attributes FileAttributes `json:"attr,omitempty"`
Encryption string `json:"e,omitempty"`
ReplaceFile uint `json:"r,omitempty"`
Size int64 `json:"s"`
}
UploadRequest contains file info (and a file)
type UploadResponse ¶
type UploadResponse struct {
FileID uint `json:"fileID"`
Filename string `json:"filename"`
PublicFilename string `json:"publicFilename,omitempty"`
}
UploadResponse response for uploading file
type UploadType ¶
type UploadType uint8
UploadType type of upload
const ( FileUploadType UploadType = iota URLUploadType )
Available upload types