netstorage

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

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

Go to latest
Published: Nov 23, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

README

Build Status Go Report Card GoDoc License

NetstorageKit-Golang: Akamai Netstorage API for Go

NetstorageKit-Golang is Akamai Netstorage (File/Object Store) API for Go 1.4+.

Important

Akamai does not maintain or regulate this package. While it can be incorporated to assist you in API use, Akamai Technical Support will not offer assistance and Akamai cannot be held liable if issues arise from its use.

Installation

To install Netstorage API for Go:

$ go get github.com/akamai/netstoragekit-golang

Example

package main

import (
  "fmt"
  "github.com/akamai/netstoragekit-golang"
  "./secrets" // in the .gitignore file
)

func main() {
  nsHostname := "astin-nsu.akamaihd.net"
  nsKeyname  := "astinapi"
  nsKey := secrets.KEY // Don't expose nsKey on public repository.
  nsCpcode := "360949"

  ns := netstorage.NewNetstorage(nsHostname, nsKeyname, nsKey, false)

  localSource := "hello.txt"
  nsDestination := fmt.Sprintf("/%s/hello.txt", nsCpcode) // or "/%s/" is same. 

  res, body, err := ns.Upload(localSource, nsDestination)
  if err != nil {
      // Do something
  }

  if res.StatusCode == 200 {
      fmt.Printf(body)
  }
}

Methods

ns.Delete(netstoragePath)
ns.Dir(netstoragePath)
ns.Download(netstorageSource, localDestintation)
ns.Du(netstoragePath)
ns.Mkdir(netstoragePath + newDirectory)
ns.Mtime(netstoragePath, mTime) // ex) mTime: time.Now().Unix()
ns.QuickDelete(netstorageDir) // needs to the privilege on the CP Code
ns.Rename(netstorageTarget, netstorageDestination)
ns.Rmdir(netstorageDir) // remove empty direcoty
ns.Stat(netstoragePath)
ns.Symlink(netstorageTarget, netstorageDestination)
ns.Upload(localSource, netstorageDestination)

// INFO: can "Upload" Only a single file, not directory.

Test

You can test all above methods with the unittest script (NOTE: You should input nsHostname, nsKeyname, nsKey and nsCpcode in the script):

$ go test
### Netstorage Test ###
[TEST] Dir /360949 done
[TEST] Mkdir /360949/nst_1477474457 done
[TEST] Upload nst_1477474457.txt to /360949/nst_1477474457/nst_1477474457.txt done
[TEST] Du /360949/nst_1477474457 done
[TEST] Mtime /360949/nst_1477474457/nst_1477474457.txt done
[TEST] Stat /360949/nst_1477474457/nst_1477474457.txt done
[TEST] Symlink /360949/nst_1477474457/nst_1477474457.txt to /360949/nst_1477474457/nst_1477474457.txt_lnk done
[TEST] Rename /360949/nst_1477474457/nst_1477474457.txt to /360949/nst_1477474457/nst_1477474457.txt_rename done
[TEST] Download /360949/nst_1477474457/nst_1477474457.txt done
[TEST] delete /360949/nst_1477474457/nst_1477474457.txt_rename done
[TEST] delete /360949/nst_1477474457/nst_1477474457.txt_lnk done
[TEST] rmdir /360949/nst_1477474457 done

### Error Test ###
[TEST] Dir: netstorage invalid path test done
[TEST] Upload: local invalid path test done
[TEST] Download: netstorage directory path test done

PASS
[TEARDOWN] remove nst_1477474457.txt from local done
[TEARDOWN] remove nst_1477474457.txt_rename from local done
ok  	github.com/akamai/netstoragekit-golang	x.xxxs

Author

Astin Choi (achoi@akamai.com)

License

Copyright 2016 Akamai Technologies, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Documentation

Overview

Package netstorage provides interfacing the Akamai Netstorage(File/Object Store) API http(s) call

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Netstorage

type Netstorage struct {
	Hostname string
	Keyname  string
	Key      string
	Ssl      string
	Client   *http.Client
}

Netstorage struct provides all the necessary fields to create authorization headers. They are on the Akamai Netstorage account page. Hostname format should be "-nsu.akamaihd.net" and Note that don't expose Key on public repository. "Ssl" element is decided by "NetNetstorage" function - string "s" means https and "" does http.

func NewNetstorage

func NewNetstorage(hostname, keyname, key string, ssl bool) *Netstorage

NewNetstorage func creates and initiates Netstorage struct. ssl parameter decides https(true) and http(false) which means "s" and "".

func (*Netstorage) Delete

func (ns *Netstorage) Delete(nsPath string) (*http.Response, string, error)

Delete deletes an object/symbolic link

func (*Netstorage) Dir

func (ns *Netstorage) Dir(nsPath string) (*http.Response, string, error)

Dir returns the directory structure

func (*Netstorage) Download

func (ns *Netstorage) Download(path ...string) (*http.Response, string, error)

Download returns the string "Download done" when the download completes. The first parameter is Netstorage source path and the second is Local destination path. If you put only the first parameter, it downloads to current local path with the first parameter's file name. From the third parameters will be ignored. Note that you can downlad only a file, not a directory.

func (*Netstorage) Du

func (ns *Netstorage) Du(nsPath string) (*http.Response, string, error)

Du returns the disk usage information for a directory

func (*Netstorage) Mkdir

func (ns *Netstorage) Mkdir(nsPath string) (*http.Response, string, error)

Mkdir creates an empty directory

func (*Netstorage) Mtime

func (ns *Netstorage) Mtime(nsPath string, mtime int64) (*http.Response, string, error)

Mtime changes a file’s mtime

func (*Netstorage) QuickDelete

func (ns *Netstorage) QuickDelete(nsPath string) (*http.Response, string, error)

QuickDelete deletes a directory (i.e., recursively delete a directory tree) In order to use this func, you need to the privilege on the CP Code.

func (*Netstorage) Rename

func (ns *Netstorage) Rename(nsTarget, nsDestination string) (*http.Response, string, error)

Rename renames a file or symbolic link.

func (*Netstorage) Rmdir

func (ns *Netstorage) Rmdir(nsPath string) (*http.Response, string, error)

Rmdir deletes an empty directory

func (*Netstorage) Stat

func (ns *Netstorage) Stat(nsPath string) (*http.Response, string, error)

Stat returns the information about an object structure

func (ns *Netstorage) Symlink(nsTarget, nsDestination string) (*http.Response, string, error)

Symlink creates a symbolic link.

func (*Netstorage) Upload

func (ns *Netstorage) Upload(localSource, nsDestination string) (*http.Response, string, error)

Upload uploads an object. The first parameter is the local source path and the second is the Netstorage destination path. If you put the directory path on "nsDestination" parameter, that filename will be the "localSource" parameter filename. Note that you can upload only a file, not a directory.

Jump to

Keyboard shortcuts

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