apiprovider

package
v0.0.0-...-55524bd Latest Latest
Warning

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

Go to latest
Published: May 30, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DocTypeEnum       = enumset.New(nil)
	DocTypeRaw        = DocTypeEnum.MustReg("raw")
	DocTypeSwag       = DocTypeEnum.MustReg("swag")
	DocTypeCurl       = DocTypeEnum.MustReg("curl")
	DocTypeJavascript = DocTypeEnum.MustReg("javascript")
	DocTypePython     = DocTypeEnum.MustReg("python")
)

doc type define

Functions

func DoHTTPRequestResp

func DoHTTPRequestResp(c *gin.Context, req *RequestReq,
	f func(c context.Context, req *RequestReq) (*RequestResp, error))

DoHTTPRequestResp response a universal api request

func RegistAPIProvider

func RegistAPIProvider(provider Provider) error

RegistAPIProvider regist api provider

Types

type APIDoc

type APIDoc struct {
	URL    string      `json:"url"`
	Method string      `json:"method"`
	Desc   string      `json:"desc"`
	Input  interface{} `json:"input"`
	Output interface{} `json:"output"`
}

APIDoc is api doc structure

type Provider

type Provider interface {
	APIType() string
	QueryDoc(c context.Context, req *QueryDocReq) (*QueryDocResp, error)
	Request(c context.Context, req *RequestReq) (*RequestResp, error)
}

Provider is the interface that provide api service

type QueryDocReq

type QueryDocReq struct {
	APIType    string `json:"-" binding:"-"`
	APIPath    string `json:"-" binding:"-"`
	DocType    string `json:"docType" binding:"max=64"`
	TitleFirst bool   `json:"titleFirst"`
}

QueryDocReq is request of api doc

type QueryDocResp

type QueryDocResp struct {
	Title   string          `json:"title"`
	APIPath string          `json:"apiPath"`
	DocType string          `json:"docType"`
	Doc     json.RawMessage `json:"doc"`
}

QueryDocResp is response of api doc

func APIQueryDoc

func APIQueryDoc(c context.Context, req *QueryDocReq) (*QueryDocResp, error)

APIQueryDoc query an api doc

type RequestReq

type RequestReq struct {
	Owner          string          `json:"-"`
	APIService     string          `json:"-" binding:"-"` // NOTE: optional, use specified service
	APIServiceArgs string          `json:"-" binding:"-"` // 	   optional, use specified service args
	APIPath        string          `json:"-" binding:"-"`
	APIType        string          `json:"-" binding:"-"`
	Method         string          `json:"-" binding:"-"`
	Body           json.RawMessage `json:"-"` // input json string
	Header         http.Header     `json:"-"` // input header
}

RequestReq is api request arg

type RequestResp

type RequestResp struct {
	APIPath    string          `json:"apiPath"`  //
	Response   json.RawMessage `json:"response"` // response json string
	Header     http.Header     `json:"header"`   // response header(cookies)
	StatusCode int             `jons:"statusCode"`
	Status     string          `json:"status"`
}

RequestResp is api request response

func APIRequest

func APIRequest(c context.Context, req *RequestReq) (*RequestResp, error)

APIRequest request an api

Jump to

Keyboard shortcuts

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