Documentation ¶
Index ¶
- func CheckApiAlive() bool
- func DownloadFile(token string, fileId string, writer io.Writer, cryptoInfo *CryptoInfo) (fileName string, numBytes int64, err error)
- func GetKeyRings(publicKey string, privateKey string, passwd []byte) (public *crypto.KeyRing, private *crypto.KeyRing, err error)
- func GetUserDisk(token string, disk string) (*Disk, *CryptoInfo, error)
- func GetUserID(token string) (string, error)
- func KtCustomClient() *http.Client
- func MapToStruct[Object any](m map[string]interface{}) (*Object, error)
- func ScanOrDefault(prompt, defaultValue string) (input string)
- func SetInteractiveMode(interactive bool)
- func SetLogger(logger Logger)
- func UploadFile(token string, name string, rewriteMime string, disk string, folder string, ...) (fileId string, err error)
- type ApiResponse
- type CryptoInfo
- type Disk
- type DisksInfo
- type DownloadResponse
- type File
- type FileGetByIdResponse
- type FilesGetResponse
- type Folder
- type Logger
- type UploadResult
- type UserInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CheckApiAlive ¶
func CheckApiAlive() bool
CheckApiAlive checks if the API is alive by sending a GET request to the /ping endpoint
func DownloadFile ¶
func DownloadFile(token string, fileId string, writer io.Writer, cryptoInfo *CryptoInfo) (fileName string, numBytes int64, err error)
DownloadFile downloads a file from the cloud. If the file is encrypted, it will be decrypted using the provided. If the file is encrypted and no crypto info provided, it will return an error. You need to provide at least your crypto password in CryptoInfo to decrypt the file. If no keys are provided, it will try to get the crypto info from the server and decrypt your key with the password.
func GetKeyRings ¶
func GetKeyRings(publicKey string, privateKey string, passwd []byte) (public *crypto.KeyRing, private *crypto.KeyRing, err error)
GetKeyRings gets the public and private key rings from the armored keys
func GetUserDisk ¶
func GetUserDisk(token string, disk string) (*Disk, *CryptoInfo, error)
GetUserDisk returns the user's default disk or the disk with the desired id. It also returns the crypto info for the disk
func GetUserID ¶
GetUserID checks if the token is valid by calling auth.getMe method and returns the user id
func KtCustomClient ¶
KtCustomClient returns a custom http client for ktCloud API It has a timeout of 5 seconds and transport with a timeout of 3 seconds
func MapToStruct ¶
MapToStruct converts a map to a struct. It is useful when we need to convert a json response to a struct
func ScanOrDefault ¶
ScanOrDefault scans user input and returns it. If the input is empty, it returns the default value. Input is not scanned in non-interactive mode and the default value is returned
func SetInteractiveMode ¶
func SetInteractiveMode(interactive bool)
SetInteractiveMode sets the interactive mode. If it is set to true, the library will ask for user input. By default, the library is not interactive. Interactive mode is used for CLI applications when you need to ask for user input.
func SetLogger ¶
func SetLogger(logger Logger)
SetLogger sets the logger for the library. By default, the library doesn't log anything. You can set your own logger using this function, but it's not required
func UploadFile ¶
func UploadFile(token string, name string, rewriteMime string, disk string, folder string, cryptoInfo *CryptoInfo, reader io.Reader) (fileId string, err error)
UploadFile uploads a file to the cloud. If encryption is enabled, it will encrypt the file before uploading. The file will be encrypted using the public key provided in the CryptoInfo struct. You need public key to encrypt the file. If you don't have the public key, you can get it from the server using the GetCryptoInfo function.
Types ¶
type ApiResponse ¶
type ApiResponse struct { ID uint `mapstructure:"id"` Error struct { Code uint `mapstructure:"code"` Message string `mapstructure:"message"` } `mapstructure:"error,omitempty"` Result map[string]interface{} `mapstructure:"result,omitempty"` }
ApiResponse is the basic mapstructure-RPC response structure
func ApiRequest ¶
func ApiRequest(token string, method string, params map[string]interface{}) (*ApiResponse, error)
ApiRequest sends a JSON-RPC request to the API. Token can be rewritten in the params map
type CryptoInfo ¶
type CryptoInfo struct { // EncryptedCryptoKey is the encrypted crypto key received from the server. You should decrypt it with a password EncryptedCryptoKey string // RawCryptoKey is the decrypted crypto key. //You can use it for encryption/decryption. //It usually is not provided by the server, you should decrypt EncryptedCryptoKey with a password RawCryptoKey string // PublicKey is the public key of the user. It is used for encryption and signature verification PublicKey string // Password is used to decrypt the EncryptedCryptoKey, also it is used as passphrase for the private key Password string }
CryptoInfo is a struct that holds all the necessary information for encryption/decryption
func GetCryptoInfo ¶
func GetCryptoInfo(token string, disk string, password string) (*CryptoInfo, error)
GetCryptoInfo gets the CryptoInfo from the server. It decrypts the crypto key if it is encrypted and a password is provided
func (*CryptoInfo) IsCryptoReady ¶
func (c *CryptoInfo) IsCryptoReady() bool
IsCryptoReady checks if the CryptoInfo is ready for encryption/decryption. It should have the crypto key to be decrypted
func (*CryptoInfo) TryGetReady ¶
func (c *CryptoInfo) TryGetReady(token string, disk string) error
TryGetReady tries to get the CryptoInfo ready for encryption/decryption. It tries to decrypt the key with the password.
type DownloadResponse ¶
type File ¶
type File struct { Date int `mapstructure:"date"` Disk string `mapstructure:"disk"` Encrypted bool `mapstructure:"encrypted"` Folder string `mapstructure:"folder"` ID string `mapstructure:"id"` Mime string `mapstructure:"mime"` Name string `mapstructure:"name"` NameCrypto string `mapstructure:"name_crypto"` Rating int `mapstructure:"rating"` Size int `mapstructure:"size"` Text string `mapstructure:"text"` Type string `mapstructure:"type"` TypeDesc string `mapstructure:"type_desc"` URLSecret string `mapstructure:"url_secret"` }
type FileGetByIdResponse ¶
type FilesGetResponse ¶
type Logger ¶
type Logger func(content string, params ...interface{})
Logger is a function type used to log messages This library doesn't log anything by default. You can set your own logger using SetLogger function