doapi

package module
v0.0.0-...-0bbf12d Latest Latest
Warning

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

Go to latest
Published: May 4, 2019 License: Apache-2.0 Imports: 21 Imported by: 97

README

Golang binding for DO API

DO is IIJ DNS outsource service.

Install

  • go get -u github.com/iij/doapi

Usage for Golang users

package main

// Usage:
//   export IIJAPI_ACCESS_KEY=<YOUR ACCESSS KEY>
//   export IIJAPI_SECRET_KEY=<YOUR SECRET KEY>
//   export DOSERVICECODE=<YOUR DO CODE>

import (
	"log"
	"os"

	"github.com/iij/doapi"
	"github.com/iij/doapi/protocol"
)

func main() {
	api := doapi.NewAPI(os.Getenv("IIJAPI_ACCESS_KEY"), os.Getenv("IIJAPI_SECRET_KEY"))

    // List zones
	request := protocol.ZoneListGet{ DoServiceCode: os.Getenv("DOSERVICECODE"), }
	response := protocol.ZoneListGetResponse{}
	if err := doapi.Call(*api, request, &response); err == nil {
		for _, zone := range response.ZoneList { 
			log.Println("zone", zone)
		}
	}
}

Documentation

Overview

Package doapi : DO APIクライアントモジュール

Index

Constants

View Source
const (
	HmacSHA1          = "HmacSHA1"
	HmacSHA256        = "HmacSHA256"
	SignatureVersion2 = "2"
	APIVersion        = "20140601"
	EndpointJSON      = "https://do.api.iij.jp/"
	// EndpointJSON = "http://localhost:9999/"
	TimeLayout      = "2006-01-02T15:04:05Z"
	PostContentType = "application/json"
)

Variables

This section is empty.

Functions

func ArgumentList

func ArgumentList(arg protocol.CommonArg) (required, optional []string)

ArgumentList API引数のリストを求める。必須とオプションに分類

func ArgumentListType

func ArgumentListType(arg protocol.CommonArg) (toURI, toQuery, toJSON []string)

ArgumentListType API引数のリストを求める。URI埋め込み、クエリストリング、JSONに分類

func Call

func Call(api API, arg protocol.CommonArg, resp interface{}) (err error)

Call API呼び出しを実行し、レスポンスを得る

func CallWithMap

func CallWithMap(api API, name string, data map[string]string, resp map[string]interface{}) error

CallWithMap API呼び出しを実行する。引数と戻り値が構造体ではなくmap

func CustomEscape

func CustomEscape(v string) string

CustomEscape escape string

func GetBody

func GetBody(arg protocol.CommonArg) string

GetBody API呼び出しのリクエストボディ(JSON文字列)を求める

func GetParam

func GetParam(api API, arg protocol.CommonArg) *url.URL

GetParam APIのクエリストリング部分を求める

func GetPath

func GetPath(arg protocol.CommonArg) string

GetPath APIのURIのパス部分を求める

func String2Sign

func String2Sign(method string, header http.Header, param url.URL) string

String2Sign get string to calculate signature

func Validate

func Validate(arg protocol.CommonArg) error

Validate APIの必須引数が入っているかどうかをチェック

func ValidateMap

func ValidateMap(name string, data map[string]string) error

ValidateMap APIの必須引数が入っているかどうかをチェック

Types

type API

type API struct {
	AccessKey  string
	SecretKey  string
	Endpoint   string
	SignMethod string
	Expires    time.Duration
	Insecure   bool
}

API の呼び出し先に関連する構造

func NewAPI

func NewAPI(accesskey, secretkey string) *API

NewAPI API構造体のコンストラクタ

func (API) Get

func (a API) Get(param url.URL) (resp *http.Response, err error)

Get : low-level Get

func (API) PostSome

func (a API) PostSome(method string, param url.URL, body interface{}) (resp *http.Response, err error)

PostSome : low-level Call

func (API) Sign

func (a API) Sign(method string, header http.Header, param url.URL, signmethod string) http.Header

Sign get signature string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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