api

package
Version: v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2021 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrorTypeParamaterError  string = "ParameterError"
	ErrorTypeNotFound        string = "NotFound"
	ErrorTypeTooManyRequests string = "TooManyRequests"
	ErrorTypeSystemError     string = "SystemError"
	ErrorTypeGatewayTimeout  string = "GatewayTimeout"
)
View Source
const DefaultEndpoint = "https://api.dns-platform.jp/dpf/v1"

Variables

This section is empty.

Functions

func IsAuthError

func IsAuthError(err error) bool

func IsBadResponse added in v0.3.0

func IsBadResponse(err error, f func(b *BadResponse) bool) bool

func IsErrMsg added in v0.3.0

func IsErrMsg(err error, msg string) bool

func IsErrType added in v0.3.0

func IsErrType(err error, name string) bool

func IsErrorCode

func IsErrorCode(err error, code string) (bool, string)

func IsErrorCodeAttribute

func IsErrorCodeAttribute(err error, code string, attribute string) bool

func IsGatewayTimeout added in v0.3.0

func IsGatewayTimeout(err error) bool

func IsInvalidSchema

func IsInvalidSchema(err error) bool

func IsNotFound

func IsNotFound(err error) bool

func IsParameterError added in v0.3.0

func IsParameterError(err error) bool

func IsRequestFormatError added in v0.3.0

func IsRequestFormatError(err error) bool

func IsStatusCode added in v0.3.0

func IsStatusCode(err error, code int) bool

func IsSystemError added in v0.3.0

func IsSystemError(err error) bool

func IsTooManyRequests added in v0.3.0

func IsTooManyRequests(err error) bool

func MarshalApply

func MarshalApply(body interface{}) ([]byte, error)

Marshal for apply request

func MarshalCreate

func MarshalCreate(body interface{}) ([]byte, error)

Marshal for create request

func MarshalOutput

func MarshalOutput(spec Spec) ([]byte, error)

Marshal for file format

func MarshalUpdate

func MarshalUpdate(body interface{}) ([]byte, error)

Marshal for update request

func UnMarshalInput

func UnMarshalInput(bs []byte, obj Object) error

UnMarshal for file format

func UnmarshalRead

func UnmarshalRead(bs []byte, o interface{}) error

Unmarshal api response

Types

type Action

type Action string
var (
	ActionCreate Action = "Create"
	ActionRead   Action = "Read"
	ActionList   Action = "List"
	ActionUpdate Action = "Update"
	ActionDelete Action = "Delete"
	ActionCount  Action = "Count"
	ActionCancel Action = "Cancel"
	ActionApply  Action = "Apply"

	Actions = []Action{
		ActionCreate,
		ActionRead,
		ActionList,
		ActionUpdate,
		ActionDelete,
		ActionCount,
		ActionCancel,
		ActionApply,
	}
)

func (Action) ToMethod

func (a Action) ToMethod() string

type AsyncResponse

type AsyncResponse struct {
	ResponseCommon `read:",inline"`
	JobsUrl        string `read:"jobs_url"`
}

type BadResponse

type BadResponse struct {
	ResponseCommon `read:",inline"`
	StatusCode     int          `read:"-"`
	ErrorType      string       `read:"error_type"`
	ErrorMessage   string       `read:"error_message"`
	ErrorDetails   ErrorDetails `read:"error_details"`
}

func (*BadResponse) Error

func (r *BadResponse) Error() string

func (*BadResponse) IsAuthError added in v0.3.0

func (r *BadResponse) IsAuthError() bool

func (*BadResponse) IsErrMsg added in v0.3.0

func (r *BadResponse) IsErrMsg(msg string) bool

func (*BadResponse) IsErrType added in v0.3.0

func (r *BadResponse) IsErrType(name string) bool

func (*BadResponse) IsErrorCode added in v0.3.0

func (r *BadResponse) IsErrorCode(code string) (bool, string)

func (*BadResponse) IsErrorCodeAttribute added in v0.3.0

func (r *BadResponse) IsErrorCodeAttribute(code string, attribute string) bool

func (*BadResponse) IsGatewayTimeout added in v0.3.0

func (r *BadResponse) IsGatewayTimeout() bool

func (*BadResponse) IsInvalidSchema added in v0.3.0

func (r *BadResponse) IsInvalidSchema() bool

func (*BadResponse) IsNotFound added in v0.3.0

func (r *BadResponse) IsNotFound() bool

func (*BadResponse) IsParameterError added in v0.3.0

func (r *BadResponse) IsParameterError() bool

func (*BadResponse) IsRequestFormatError added in v0.3.0

func (r *BadResponse) IsRequestFormatError() bool

func (*BadResponse) IsStatusCode added in v0.3.0

func (r *BadResponse) IsStatusCode(code int) bool

func (*BadResponse) IsSystemError added in v0.3.0

func (r *BadResponse) IsSystemError() bool

func (*BadResponse) IsTooManyRequests added in v0.3.0

func (r *BadResponse) IsTooManyRequests() bool

type Client

type Client struct {
	Endpoint string
	Token    string

	Client       *http.Client
	LastRequest  *RequestInfo
	LastResponse *ResponseInfo
	// contains filtered or unexported fields
}

func NewClient

func NewClient(token string, endpoint string, logger Logger) *Client

func (*Client) Apply

func (c *Client) Apply(s Spec, body interface{}) (requestId string, err error)

func (*Client) Cancel

func (c *Client) Cancel(s Spec) (requestId string, err error)

func (*Client) Count

func (c *Client) Count(s CountableListSpec, keywords SearchParams) (requestId string, err error)

func (*Client) Create

func (c *Client) Create(s Spec, body interface{}) (requestId string, err error)

func (*Client) Delete

func (c *Client) Delete(s Spec) (requestId string, err error)

func (*Client) Do

func (c *Client) Do(spec Spec, action Action, body interface{}, params SearchParams) (requestId string, err error)

func (*Client) List

func (c *Client) List(s ListSpec, keywords SearchParams) (requestId string, err error)

func (*Client) ListALL

func (c *Client) ListALL(s CountableListSpec, keywords SearchParams) (requestId string, err error)

func (*Client) Read

func (c *Client) Read(s Spec) (requestId string, err error)

func (*Client) Update

func (c *Client) Update(s Spec, body interface{}) (requestId string, err error)

func (*Client) WatchList

func (c *Client) WatchList(ctx context.Context, interval time.Duration, s ListSpec, keyword SearchParams) error

ctx should set Deadline or Timeout interval must be grater than equals to 1s s is ListAble Spec

func (*Client) WatchListAll

func (c *Client) WatchListAll(ctx context.Context, interval time.Duration, s CountableListSpec, keyword SearchParams) error

ctx should set Deadline or Timeout interval must be grater than equals to 1s s is CountableListSpec Spec

func (*Client) WatchRead

func (c *Client) WatchRead(ctx context.Context, interval time.Duration, s Spec) error

ctx should set Deadline or Timeout interval must be grater than equals to 1s s is Readable Spec

type ClientInterface added in v0.3.0

type ClientInterface interface {
	Do(spec Spec, action Action, body interface{}, params SearchParams) (requestId string, err error)
	Read(s Spec) (requestId string, err error)
	List(s ListSpec, keywords SearchParams) (requestId string, err error)
	ListALL(s CountableListSpec, keywords SearchParams) (requestId string, err error)
	Count(s CountableListSpec, keywords SearchParams) (requestId string, err error)
	Update(s Spec, body interface{}) (requestId string, err error)
	Create(s Spec, body interface{}) (requestId string, err error)
	Apply(s Spec, body interface{}) (requestId string, err error)
	Delete(s Spec) (requestId string, err error)
	Cancel(s Spec) (requestId string, err error)
	WatchRead(ctx context.Context, interval time.Duration, s Spec) error
	WatchList(ctx context.Context, interval time.Duration, s ListSpec, keyword SearchParams) error
	WatchListAll(ctx context.Context, interval time.Duration, s CountableListSpec, keyword SearchParams) error
}

type CommonSearchParams

type CommonSearchParams struct {
	Type   SearchType `url:"type,omitempty"`
	Offset int32      `url:"offset,omitempty"`
	Limit  int32      `url:"limit,omitempty"`
}

func (*CommonSearchParams) GetLimit

func (k *CommonSearchParams) GetLimit() int32

func (*CommonSearchParams) GetOffset

func (k *CommonSearchParams) GetOffset() int32

func (*CommonSearchParams) GetType

func (k *CommonSearchParams) GetType() SearchType

func (*CommonSearchParams) GetValues

func (s *CommonSearchParams) GetValues() (url.Values, error)

func (*CommonSearchParams) SetLimit

func (k *CommonSearchParams) SetLimit(limit int32)

func (*CommonSearchParams) SetOffset

func (k *CommonSearchParams) SetOffset(offset int32)

func (*CommonSearchParams) SetType

func (k *CommonSearchParams) SetType(t SearchType)

type Count

type Count struct {
	Count int32 `read:"count" json:"-"`
}

func (*Count) GetCount

func (c *Count) GetCount() int32

func (*Count) SetCount

func (c *Count) SetCount(v int32)

type CountResponse

type CountResponse struct {
	ResponseCommon `read:",inline"`
	Result         Count `read:"result"`
}

type CountableListSpec

type CountableListSpec interface {
	ListSpec
	SetCount(int32)
	GetCount() int32
	GetMaxLimit() int32
	AddItem(interface{}) bool
	ClearItems()
}

type ErrorDetail

type ErrorDetail struct {
	Code      string `read:"code"`
	Attribute string `read:"attribute"`
}

func (ErrorDetail) Error

func (e ErrorDetail) Error() string

type ErrorDetails

type ErrorDetails []ErrorDetail

func (ErrorDetails) Error

func (e ErrorDetails) Error() string

type Initializer

type Initializer interface {
	Init()
}

type KeywordsBoolean

type KeywordsBoolean []types.Boolean

+k8s:deepcopy-gen=false

func (KeywordsBoolean) EncodeValues

func (c KeywordsBoolean) EncodeValues(key string, v *url.Values) error

type KeywordsFavorite

type KeywordsFavorite []types.Favorite

+k8s:deepcopy-gen=false

func (KeywordsFavorite) EncodeValues

func (c KeywordsFavorite) EncodeValues(key string, v *url.Values) error

type KeywordsId

type KeywordsId []int64

+k8s:deepcopy-gen=false

func (KeywordsId) Validate

func (s KeywordsId) Validate() bool

type KeywordsState

type KeywordsState []types.State

+k8s:deepcopy-gen=false

func (KeywordsState) EncodeValues

func (c KeywordsState) EncodeValues(key string, v *url.Values) error

type KeywordsString

type KeywordsString []string

+k8s:deepcopy-gen=false

func (KeywordsString) Validate

func (s KeywordsString) Validate() bool

type ListSpec

type ListSpec interface {
	Spec
	Initializer
	GetItems() interface{}
	Len() int
	Index(int) interface{}
}

type Logger

type Logger interface {
	Tracef(format string, args ...interface{})
	Debugf(format string, args ...interface{})
	Infof(format string, args ...interface{})
	Errorf(format string, args ...interface{})
}

logger interface

type Object

type Object interface {
	DeepCopyObject() Object
}

type OutputFrame

type OutputFrame struct {
	meta.KindVersion `json:",inline"`
	Spec             Object `json:"spec"`
}

file format frame

type RawResponse

type RawResponse struct {
	ResponseCommon `read:",inline"`
	Result         json.RawMessage `read:"result"`
	Results        json.RawMessage `read:"results"`
}

type RequestInfo

type RequestInfo struct {
	Method string
	Url    string
	Body   []byte
}

type ResponseCommon

type ResponseCommon struct {
	RequestId string `read:"request_id"`
}

type ResponseInfo

type ResponseInfo struct {
	Response *http.Response
	Body     []byte
}

type RowSearchParams

type RowSearchParams struct {
	url.Values
}

func NewRowSearchParams

func NewRowSearchParams(queryString string) (*RowSearchParams, error)

func (RowSearchParams) GetLimit

func (r RowSearchParams) GetLimit() int32

func (RowSearchParams) GetOffset

func (r RowSearchParams) GetOffset() int32

func (*RowSearchParams) GetValues

func (r *RowSearchParams) GetValues() (url.Values, error)

func (RowSearchParams) SetLimit

func (r RowSearchParams) SetLimit(limit int32)

func (RowSearchParams) SetOffset

func (r RowSearchParams) SetOffset(offset int32)

type SearchDate

type SearchDate time.Time

+k8s:deepcopy-gen=false

type SearchLimit

type SearchLimit int32

+k8s:deepcopy-gen=false

func (SearchLimit) Validate

func (s SearchLimit) Validate() bool

type SearchOffset

type SearchOffset int32

+k8s:deepcopy-gen=false

func (SearchOffset) Validate

func (s SearchOffset) Validate() bool

type SearchOrder

type SearchOrder string

+k8s:deepcopy-gen=false

var (
	SearchOrderASC  SearchOrder = "ASC"
	SearchOrderDESC SearchOrder = "DESC"
)

func (SearchOrder) Validate

func (s SearchOrder) Validate() bool

type SearchParams

type SearchParams interface {
	GetValues() (url.Values, error)
	GetOffset() int32
	SetOffset(int32)
	GetLimit() int32
	SetLimit(int32)
}

type SearchType

type SearchType string

+k8s:deepcopy-gen=false

var (
	SearchTypeAND SearchType = "AND"
	SearchTypeOR  SearchType = "OR"
)

func (SearchType) Validate

func (s SearchType) Validate() bool

type Spec

type Spec interface {
	Object
	GetName() string
	GetGroup() string
	GetPathMethod(Action) (string, string)
}

type StdLogger

type StdLogger struct {
	*log.Logger
	LogLevel int
}

simple logger change better logger as you like.

func NewStdLogger added in v0.3.0

func NewStdLogger(out io.Writer, prefix string, flag int, level int) *StdLogger

func (*StdLogger) Debugf

func (s *StdLogger) Debugf(format string, args ...interface{})

func (*StdLogger) Errorf

func (s *StdLogger) Errorf(format string, args ...interface{})

func (*StdLogger) Infof

func (s *StdLogger) Infof(format string, args ...interface{})

func (*StdLogger) Tracef

func (s *StdLogger) Tracef(format string, args ...interface{})

Jump to

Keyboard shortcuts

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