restapi

package
v0.0.0-...-9b07614 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2023 License: MulanPSL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package restapi provides primitives to interact with the openapi HTTP API.

Code generated by github.com/deepmap/oapi-codegen version v1.8.1 DO NOT EDIT.

restapi package provides the restful api interface based on openapi standard.

Index

Constants

View Source
const (
	Servermgt_oauth2Scopes = "servermgt_oauth2.Scopes"
)

Variables

This section is empty.

Functions

func CreateAuthValidator

func CreateAuthValidator(v JWSValidator) (echo.MiddlewareFunc, error)

CreateAuthValidator creates auth validator in order to start the server smoothly.

func CreateTestAuthToken

func CreateTestAuthToken() ([]byte, error)

CreateTestAuthToken creates test auth token and returns token.

func GetSwagger

func GetSwagger() (swagger *openapi3.T, err error)

GetSwagger returns the Swagger specification corresponding to the generated code in this file. The external references of Swagger specification are resolved. The logic of resolving external references is tightly connected to "import-mapping" feature. Externally referenced files must be embedded in the corresponding golang packages. Urls can be supported but this task was out of the scope.

func NewGetConfigRequest

func NewGetConfigRequest(server string) (*http.Request, error)

NewGetConfigRequest generates requests for GetConfig

func NewPostConfigRequest

func NewPostConfigRequest(server string) (*http.Request, error)

NewPostConfigRequest generates requests for PostConfig

func PathToRawSpec

func PathToRawSpec(pathToFile string) map[string]func() ([]byte, error)

Constructs a synthetic filesystem for resolving external references when loading openapi specifications.

func RegisterHandlers

func RegisterHandlers(router EchoRouter, si ServerInterface)

RegisterHandlers adds each server route to the EchoRouter.

func RegisterHandlersWithBaseURL

func RegisterHandlersWithBaseURL(router EchoRouter, si ServerInterface, baseURL string)

Registers handlers, and prepends BaseURL to the paths, so that the paths can be served under a prefix.

func StartServer

func StartServer(addr string)

StartServer starts a server.

Types

type Client

type Client struct {
	// The endpoint of the server conforming to this interface, with scheme,
	// https://api.deepmap.com for example. This can contain a path relative
	// to the server, such as https://api.deepmap.com/dev-test, and all the
	// paths in the swagger spec will be appended to the server.
	Server string

	// Doer for performing requests, typically a *http.Client with any
	// customized settings, such as certificate chains.
	Client HttpRequestDoer

	// A list of callbacks for modifying requests which are generated before sending over
	// the network.
	RequestEditors []RequestEditorFn
}

Client which conforms to the OpenAPI3 specification for this service.

func NewClient

func NewClient(server string, opts ...ClientOption) (*Client, error)

Creates a new Client, with reasonable defaults

func (*Client) GetConfig

func (c *Client) GetConfig(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

func (*Client) PostConfig

func (c *Client) PostConfig(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

type ClientInterface

type ClientInterface interface {
	// GetConfig request
	GetConfig(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)

	// PostConfig request
	PostConfig(ctx context.Context, reqEditors ...RequestEditorFn) (*http.Response, error)
}

The interface specification for the client above.

type ClientOption

type ClientOption func(*Client) error

ClientOption allows setting custom parameters during construction

func WithBaseURL

func WithBaseURL(baseURL string) ClientOption

WithBaseURL overrides the baseURL.

func WithHTTPClient

func WithHTTPClient(doer HttpRequestDoer) ClientOption

WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.

func WithRequestEditorFn

func WithRequestEditorFn(fn RequestEditorFn) ClientOption

WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.

type ClientWithResponses

type ClientWithResponses struct {
	ClientInterface
}

ClientWithResponses builds on ClientInterface to offer response payloads

func NewClientWithResponses

func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)

NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling

func (*ClientWithResponses) GetConfigWithResponse

func (c *ClientWithResponses) GetConfigWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetConfigResponse, error)

GetConfigWithResponse request returning *GetConfigResponse

func (*ClientWithResponses) PostConfigWithResponse

func (c *ClientWithResponses) PostConfigWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostConfigResponse, error)

PostConfigWithResponse request returning *PostConfigResponse

type ClientWithResponsesInterface

type ClientWithResponsesInterface interface {
	// GetConfig request
	GetConfigWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*GetConfigResponse, error)

	// PostConfig request
	PostConfigWithResponse(ctx context.Context, reqEditors ...RequestEditorFn) (*PostConfigResponse, error)
}

ClientWithResponsesInterface is the interface specification for the client with responses above.

type EchoRouter

type EchoRouter interface {
	CONNECT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	DELETE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	GET(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	HEAD(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	OPTIONS(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PATCH(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	POST(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	PUT(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
	TRACE(path string, h echo.HandlerFunc, m ...echo.MiddlewareFunc) *echo.Route
}

This is a simple interface which specifies echo.Route addition functions which are present on both echo.Echo and echo.Group, since we want to allow using either of them for path registration

type GetConfigResponse

type GetConfigResponse struct {
	Body         []byte
	HTTPResponse *http.Response
	JSON200      *string
}

func ParseGetConfigResponse

func ParseGetConfigResponse(rsp *http.Response) (*GetConfigResponse, error)

ParseGetConfigResponse parses an HTTP response from a GetConfigWithResponse call

func (GetConfigResponse) Status

func (r GetConfigResponse) Status() string

Status returns HTTPResponse.Status

func (GetConfigResponse) StatusCode

func (r GetConfigResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type HttpRequestDoer

type HttpRequestDoer interface {
	Do(req *http.Request) (*http.Response, error)
}

Doer performs HTTP requests.

The standard http.Client implements this interface.

type JWSValidator

type JWSValidator interface {
	ValidateJWS(jws string) (jwt.Token, error)
}

JWSValidator is used to validate JWS payloads and return a JWT if they're valid

type MyRestAPIServer

type MyRestAPIServer struct {
}

MyRestAPIServer means rest api server

func (*MyRestAPIServer) GetConfig

func (s *MyRestAPIServer) GetConfig(ctx echo.Context) error

(GET /config) GetConfig get tas server configuration

read config as json
  curl -X GET -H "Content-Type: application/json" http://localhost:40009/config

func (*MyRestAPIServer) PostConfig

func (s *MyRestAPIServer) PostConfig(ctx echo.Context) error

(POST /config) PostConfig modify tas server configuration

write config as json
  curl -X POST -H "Content-Type: application/json" -H "Authorization: $AUTHTOKEN" -d '{"basevalue":"testvalue"}' http://localhost:40009/config

Notice: key name must be enclosed by "" in json format!!!

type PostConfigResponse

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

func ParsePostConfigResponse

func ParsePostConfigResponse(rsp *http.Response) (*PostConfigResponse, error)

ParsePostConfigResponse parses an HTTP response from a PostConfigWithResponse call

func (PostConfigResponse) Status

func (r PostConfigResponse) Status() string

Status returns HTTPResponse.Status

func (PostConfigResponse) StatusCode

func (r PostConfigResponse) StatusCode() int

StatusCode returns HTTPResponse.StatusCode

type RequestEditorFn

type RequestEditorFn func(ctx context.Context, req *http.Request) error

RequestEditorFn is the function signature for the RequestEditor callback function

type ServerInterface

type ServerInterface interface {

	// (GET /config)
	GetConfig(ctx echo.Context) error

	// (POST /config)
	PostConfig(ctx echo.Context) error
}

ServerInterface represents all server handlers.

type ServerInterfaceWrapper

type ServerInterfaceWrapper struct {
	Handler ServerInterface
}

ServerInterfaceWrapper converts echo contexts to parameters.

func (*ServerInterfaceWrapper) GetConfig

func (w *ServerInterfaceWrapper) GetConfig(ctx echo.Context) error

GetConfig converts echo context to params.

func (*ServerInterfaceWrapper) PostConfig

func (w *ServerInterfaceWrapper) PostConfig(ctx echo.Context) error

PostConfig converts echo context to params.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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