yapi

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 8, 2022 License: MIT Imports: 13 Imported by: 0

README

go-yapi

go-yapi is a Go client for Yapi .

2022.05.08更新 修改api返回数据解析错误的问题,重写api请求调用

Installation

Install go-yapi using the "go get" command:

go get github.com/micrease/go-yapi

Documentation

Example

See Examples

Reference Projects

License

This project is released under the terms of the MIT license.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckResponse

func CheckResponse(r *http.Response) error

CheckResponse checks the API response for errors, and returns them if present. A response is considered an error if it has a status code outside the 200 range. The caller is responsible to analyze the response body. The body can contain JSON (if the error is intended) or xml.

func NewServerError

func NewServerError(resp *http.Response, httpError error) error

NewServerError creates a new Server Error

Types

type AddOrUpdateInterfaceData

type AddOrUpdateInterfaceData struct {
	Token string `json:"token" structs:"token"`
	InterfaceData
}

type AuthenticationService

type AuthenticationService struct {
	// contains filtered or unexported fields
}

AuthenticationService .

type BasicAuthTransport

type BasicAuthTransport struct {
	Username string
	Password string

	// Transport is the underlying HTTP transport to use when making requests.
	// It will default to http.DefaultTransport if nil.
	Transport http.RoundTripper
}

BasicAuthTransport is an http.RoundTripper that authenticates all requests using HTTP Basic Authentication with the provided username and password.

func (*BasicAuthTransport) Client

func (t *BasicAuthTransport) Client() *http.Client

Client returns an *http.Client that makes requests that are authenticated using HTTP Basic Authentication. This is a nice little bit of sugar so we can just get the client instead of creating the client in the calling code. If it's necessary to send more information on client init, the calling code can always skip this and set the transport itself.

func (*BasicAuthTransport) RoundTrip

func (t *BasicAuthTransport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip implements the RoundTripper interface. We just add the basic auth and return the RoundTripper for this transport type.

type CatData

type CatData struct {
	ID   int    `json:"_id" structs:"_id"`
	UID  int    `json:"uid" structs:"uid"`
	Name string `json:"name" structs:"name"`
	Desc string `json:"desc" structs:"desc"`
}

type CatMenu

type CatMenu struct {
	ErrCode int         `json:"errcode" structs:"errcode"`
	ErrMsg  string      `json:"errmsg" structs:"errmsg"`
	Data    CatMenuData `json:"data" structs:"data"`
	// contains filtered or unexported fields
}

func (*CatMenu) ToString

func (p *CatMenu) ToString() string

type CatMenuData

type CatMenuData []CatData

type CatMenuParam

type CatMenuParam struct {
	Token     string `url:"token"`
	ProjectID int    `url:"project_id"`
}

type CatMenuService

type CatMenuService struct {
	// contains filtered or unexported fields
}

CatMenuService .

func (*CatMenuService) AddOrUpdate

func (s *CatMenuService) AddOrUpdate(param *ModifyMenuParam) (*ModifyMenuResp, error)

func (*CatMenuService) Get

func (s *CatMenuService) Get(projectId int) (*CatMenu, error)

type Client

type Client struct {

	// Services used for talking to different parts of the API.
	Authentication *AuthenticationService
	Interface      *InterfaceService
	Project        *ProjectService
	CatMenu        *CatMenuService
	// contains filtered or unexported fields
}

A Client manages communication with the API.

func NewClient

func NewClient(baseURL string, apiToken string) (*Client, error)

NewClient returns a new API client. If a nil httpClient is provided, http.DefaultClient will be used.

func (*Client) Do

func (c *Client) Do(req *http.Request, v interface{}) (string, error)

Do sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred.

func (*Client) Get

func (c *Client) Get(urlStr string, body io.Reader) (string, error)

func (*Client) GetBaseURL

func (c *Client) GetBaseURL() url.URL

GetBaseURL will return you the Base URL. This is the same URL as in the NewClient constructor

func (*Client) NewMultiPartRequest

func (c *Client) NewMultiPartRequest(method, urlStr string, buf *bytes.Buffer) (*http.Request, error)

NewMultiPartRequest creates an API request including a multi-part file. A relative URL can be provided in urlStr, in which case it is resolved relative to the baseURL of the Client. If specified, the value pointed to by buf is a multipart form.

func (*Client) NewRawRequest

func (c *Client) NewRawRequest(method, urlStr string, body io.Reader) (*http.Request, error)

NewRawRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the baseURL of the Client. Allows using an optional native io.Reader for sourcing the request body.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the baseURL of the Client. If specified, the value pointed to by body is JSON encoded and included as the request body.

func (*Client) Post

func (c *Client) Post(urlStr string, body interface{}) (string, error)

type CommonResp

type CommonResp struct {
	ErrCode int    `json:"errcode" structs:"errcode"`
	ErrMsg  string `json:"errmsg" structs:"errmsg"`
}

* 接口通用返回

type EnvGlobal

type EnvGlobal struct {
	ID    string `json:"_id,omitempty" structs:"_id,omitempty"`
	Name  string `json:"name,omitempty" structs:"name,omitempty"`
	Value string `json:"value,omitempty" structs:"value,omitempty"`
}

type EnvHeader

type EnvHeader struct {
	ID    string `json:"_id,omitempty" structs:"_id,omitempty"`
	Name  string `json:"name,omitempty" structs:"name,omitempty"`
	Value string `json:"value,omitempty" structs:"value,omitempty"`
}

type Error

type Error struct {
	HTTPError     error
	ErrorMessages []string          `json:"errorMessages"`
	Errors        map[string]string `json:"errors"`
}

Error message

func (*Error) Error

func (e *Error) Error() string

Error is a short string representing the error

func (*Error) LongError

func (e *Error) LongError() string

LongError is a full representation of the error as a string

type Interface

type Interface struct {
	CommonResp
	Data InterfaceData `json:"data" structs:"data"`
	// contains filtered or unexported fields
}

func (*Interface) ToString

func (i *Interface) ToString() string

type InterfaceData

type InterfaceData struct {
	// contains filtered or unexported fields
}

type InterfaceList

type InterfaceList struct {
	ErrCode int               `json:"errcode" structs:"errcode"`
	ErrMsg  string            `json:"errmsg" structs:"errmsg"`
	Data    InterfaceListData `json:"data" structs:"data"`
	// contains filtered or unexported fields
}

func (*InterfaceList) ToString

func (i *InterfaceList) ToString() string

type InterfaceListData

type InterfaceListData struct {
	Count int             `json:"count" structs:"count"`
	Total int             `json:"total" structs:"total"`
	List  []InterfaceData `json:"list" structs:"list"`
}

type InterfaceListParam

type InterfaceListParam struct {
	Token string `url:"token,omitempty"`
	CatID int    `url:"catid,omitempty"`
	Page  int    `url:"Page"`
	Limit int    `url:"limit"`
}

type InterfaceParam

type InterfaceParam struct {
	Token string `url:"token"`
	ID    int    `url:"id"`
}

type InterfaceService

type InterfaceService struct {
	// contains filtered or unexported fields
}

InterfaceService .

func (*InterfaceService) AddOrUpdate

func (s *InterfaceService) AddOrUpdate(data *InterfaceData) (*ModifyResp, error)

func (*InterfaceService) Get

func (s *InterfaceService) Get(id int) (*Interface, error)

func (*InterfaceService) GetList

func (*InterfaceService) UploadSwagger

func (s *InterfaceService) UploadSwagger(data *string) (*ModifyResp, error)

type ModifyMenuParam

type ModifyMenuParam struct {
	ProjectID int `json:"project_id" url:"project_id"`
	CatData
}

type ModifyMenuResp

type ModifyMenuResp struct {
	CommonResp
	Data interface{} `json:"data" structs:"data"`
	// contains filtered or unexported fields
}

func (*ModifyMenuResp) ToString

func (p *ModifyMenuResp) ToString() string

type ModifyMenumReq

type ModifyMenumReq struct {
	Token string `json:"token"`
	ModifyMenuParam
}

type ModifyResp

type ModifyResp struct {
	CommonResp
	Data interface{} `json:"data" structs:"data"`
	// contains filtered or unexported fields
}

func (*ModifyResp) ToString

func (m *ModifyResp) ToString() string

type ModifyResult

type ModifyResult struct {
	Ok        int `json:"ok" structs:"ok"`
	NModified int `json:"nModified" structs:"nModified"`
	N         int `json:"n" structs:"n"`
}

type Project

type Project struct {
	ErrCode int         `json:"errcode" structs:"errcode"`
	ErrMsg  string      `json:"errmsg" structs:"errmsg"`
	Data    ProjectData `json:"data" structs:"data"`
	// contains filtered or unexported fields
}

func (*Project) ToString

func (p *Project) ToString() string

type ProjectData

type ProjectData struct {
	ID      int          `json:"_id" structs:"_id"`
	UID     int          `json:"uid" structs:"uid"`
	GroupID int          `json:"group_id" structs:"group_id"`
	Name    string       `json:"name" structs:"name"`
	Role    bool         `json:"role" structs:"role"`
	Env     []ProjectEnv `json:"env" structs:"env"`
}

type ProjectEnv

type ProjectEnv struct {
	Header []EnvHeader `json:"header,omitempty" structs:"header,omitempty"`
	Global []EnvGlobal `json:"global,omitempty" structs:"global,omitempty"`
	ID     string      `json:"_id" structs:"_id"`
	Name   string      `json:"name" structs:"name"`
	Domain string      `json:"domain" structs:"domain"`
}

type ProjectParam

type ProjectParam struct {
	Token string `url:"token"`
}

type ProjectService

type ProjectService struct {
	// contains filtered or unexported fields
}

ProjectService .

func (*ProjectService) Get

func (s *ProjectService) Get() (*Project, error)

type ReqKVItemDetail

type ReqKVItemDetail struct {
	ReqKVItemSimple
	Type     string `json:"type" structs:"type"`
	Required string `json:"required" structs:"required"`
}

type ReqKVItemSimple

type ReqKVItemSimple struct {
	Name    string `json:"name" structs:"name"`
	Value   string `json:"value" structs:"value"`
	Example string `json:"example" structs:"example"`
	Desc    string `json:"desc" structs:"desc"`
}

type UploadSwaggerReq

type UploadSwaggerReq struct {
	Type  string `json:"type" structs:"types"`
	Json  string `json:"json" structs:"jsons"`
	Merge string `json:"merge" structs:"string"`
	Token string `json:"token" structs:"token"`
	// contains filtered or unexported fields
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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