openapi

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: Apache-2.0 Imports: 16 Imported by: 0

README

OpenAPI v1

OpenAPI 签名算法

Usage

go get github.com/easyopsapis/openapi-go/v1
package main

import (
	"context"
	cmdb "github.com/easyopsapis/easyops-api-go/protorepo-cmdb"
	"github.com/easyopsapis/easyops-api-go/protorepo-cmdb/instance"
	"github.com/easyopsapis/openapi-go/v1"
	"log"
)

func main() {
	// OpenAPI服务地址: 192.168.100.162:8109
	// accessKey: c92f21653163ec91d238129c
	// secretKey: 66555962666442714948516f4c70504c4c79686d544a795172766f73506c5967
	gw, _ := openapi.NewClient("192.168.100.162:8109", "c92f21653163ec91d238129c", "66555962666442714948516f4c70504c4c79686d544a795172766f73506c5967")

	// 根据服务名封装client, 注入cmdb client中
	c := cmdb.NewClient(openapi.WrapClient("cmdbservice", gw)) // 服务名: cmdbservice

	// 利用 cmdb client 查询实例详情
	d, err := c.Instance.GetDetail(context.Background(), &instance.GetDetailRequest{
		ObjectId:   "APP",
		InstanceId: "582f3323eef19",
		Fields:     "name",
	})

	if err != nil {
		// 当请求返回错误时, 利用 gerr 包从 err 中提取 Status 信息 ( 包含错误码, 错误信息等信息 )
		status := gerr.FromError(err)
		fmt.Println(status.Code(), status.Message())
		os.Exit(1)
	}

	fmt.Println(d.Fields["name"].GetStringValue())
}

Documentation

Index

Constants

View Source
const FIELDMASK = "XXX_RestFieldMask"

Variables

This section is empty.

Functions

func NewTransport

func NewTransport(accessKey, secretKey string, options ...TransportOption) (http.RoundTripper, error)

func WrapClient

func WrapClient(name string, client *Client) giraffe.Client

func WrapClientWithScheme added in v0.0.4

func WrapClientWithScheme(name string, scheme string, client *Client) giraffe.Client

Types

type ApiKey

type ApiKey struct {
	AccessKey, SecretKey string
}

func (ApiKey) Sign

func (a ApiKey) Sign(expires time.Time, r Request) error

type Client

type Client struct {
	*restv2.Client
	// contains filtered or unexported fields
}

func NewClient

func NewClient(address, accessKey, secretKey string, options ...ClientOption) (*Client, error)

type ClientOption

type ClientOption func(*Client)

func WithClient

func WithClient(client *http.Client) ClientOption

type Middleware

type Middleware struct {
	restv2.Middleware
}

func (*Middleware) NewRequest

func (m *Middleware) NewRequest(rule giraffe.HttpRule, in interface{}) (*http.Request, error)

func (*Middleware) ParseResponse

func (m *Middleware) ParseResponse(rule giraffe.HttpRule, resp *http.Response, out interface{}) error

type Request

type Request interface {
	SetSignature(accessKey, signature string, expires time.Time)
	StringToSign() (string, error)
}

type Signer

type Signer interface {
	Sign(expires time.Time, request Request) error
}

type TransportOption

type TransportOption func(*transport)

func RoundTripper

func RoundTripper(rt http.RoundTripper) TransportOption

Jump to

Keyboard shortcuts

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