Skip to content

byteark/byteark-sdk-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ByteArk SDK for GO

Build Status

Table of contents

Installation

go get github.com/byteark/byteark-sdk-go

Usage

Now the only feature availabled is creating signed URL with ByteArk Signature Version 2.

First, import ByteArk's SDK in your code and call CreateSigner() to create Signer.

import (
    bytearkSignedURL "github.com/byteark/byteark-sdk-go"
)

The CreateSigner() required one parameter SignerOptions, which you can use provided SignerOptions via SDK.

signerOptions :=  bytearkSignedURL.SignerOptions{
    AccessID:     "2Aj6Wkge4hi1ZYLp0DBG",
    AccessSecret: "31sX5C0lcBiWuGPTzRszYvjxzzI3aCZjJi85ZyB7",
}

createSignerErr := bytearkSignedURL.CreateSigner(signerOptions)

if createSignerErr != nil {
    panic(createSignerErr)
}

After create Signer you can call Sign function via SDK. Sign() function also consume 3 parameters, url, expires and signOptions. SignOptions is also provided by the SDK. Sign() return signedURL and error.

signOptions := bytearkSignedURL.SignOptions{
    "path_prefix": "/live/",
}

signedURL, err := bytearkSignedURL.Sign(
    "https://example.cdn.byteark.com/path/to/file.png",
    1514764800,
    signOptions,
)

example

APIs

CreateSigner

func CreateSigner(options SignerOptions) error

Create and update initial value of signer in sigleton pattern.

Sign

func Sign(url string, expires int, options SignOptions) (string, error)

Sign input url with expire date and option.

Verify

func Verify(url string, now int) (bool, error)

Verfiy signedURL that already sign by sign function.

Type

SignerOptions

type SignerOptions struct {
    AccessID        string
    AccessSecret    string
    DefaultAge      int
    SkipURLEncoding bool
}

SignOptions

type SignOptions map[string]string