api

package
v0.0.0-...-6ac6f58 Latest Latest
Warning

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

Go to latest
Published: Apr 11, 2024 License: Apache-2.0, BSD-3-Clause, MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// PathV1 describe the prefix of version 1 http action.
	PathV1 = prefix + versionV1

	// PathV2 describe the prefix of version 2 http action.
	PathV2 = prefix + versionV2
)
View Source
const (
	// HeaderRemote define a http-header name which store the true source ip from requester.
	HeaderRemote = "X-Real-Ip"
)

Variables

This section is empty.

Functions

func GetAPIV1Action

func GetAPIV1Action() []*httpserver.Action

GetAPIV1Action get V1 actions

func GetAPIV2Action

func GetAPIV2Action() []*httpserver.Action

GetAPIV2Action get V1 actions

func InitActionsFunc

func InitActionsFunc() error

InitActionsFunc will call all the functions in initFunc

func MasterRequired

func MasterRequired(f restful.RouteFunction) func(req *restful.Request, resp *restful.Response)

MasterRequired wrap the api handler and make it only available for master node.

func NoLimit

func NoLimit(f restful.RouteFunction) func(req *restful.Request, resp *restful.Response)

NoLimit wrap the api handler and will process all requests.

func RegisterInitFunc

func RegisterInitFunc(f func() error)

RegisterInitFunc called by actions for registering some daemon functions and these functions will be called after flag-init and server-start

func RegisterV1Action

func RegisterV1Action(action Action)

RegisterV1Action register a handler into v1 actions means all the URL of these handlers are start with PathV1

func RegisterV2Action

func RegisterV2Action(action Action)

RegisterV2Action register a handler into v1 actions means all the URL of these handlers are start with PathV1

func ReturnRest

func ReturnRest(resp *RestResponse)

ReturnRest do the return work according to a RestResponse

Types

type Action

type Action httpserver.Action

Action describe the http handler action.

type ErrorCode

type ErrorCode interface {
	// get error string
	String() string

	// get error code int
	Int() int
}

ErrorCode describe the error from http handler

type ProcessType

type ProcessType string
const (
	ProcessMasterOnly ProcessType = "master_only"
	ProcessNoLimit    ProcessType = "no_limit"
)

type RestResponse

type RestResponse struct {
	Resp     *restful.Response
	HTTPCode int

	Data    interface{}
	ErrCode ErrorCode
	Message string
	Extra   map[string]interface{}

	WrapFunc func([]byte) []byte
}

RestResponse contains all response information need by a http handler

type ServerAPIResource

type ServerAPIResource struct {
	ActionsV1 []*httpserver.Action
	ActionsV2 []*httpserver.Action
	Rd        rd.RegisterDiscover
	Manager   manager.Manager
	Conf      *config.ServerConfig
}

ServerAPIResource describe all the server api resources

func GetAPIResource

func GetAPIResource() *ServerAPIResource

GetAPIResource get the standalone api resource instance

func (*ServerAPIResource) RegisterWebServer

func (a *ServerAPIResource) RegisterWebServer(svr *httpserver.HTTPServer) error

RegisterWebServer register all actions in api-resource into the given http server.

type ServerErrCode

type ServerErrCode int

ServerErrorCode implements the ErrorCode

const (
	ServerErrOK ServerErrCode = iota
	ServerErrInvalidParam
	ServerErrApplyResourceFailed
	ServerErrRequestTaskInfoFailed
	ServerErrUpdateHeartbeatFailed
	ServerErrReleaseResourceFailed
	ServerErrPreProcessFailed
	ServerErrRedirectFailed
	ServerErrEncodeJSONFailed
	ServerErrGetServersFailed
	ServerErrSendMessageFailed
	ServerErrUnknownMessageType
)

func (ServerErrCode) Int

func (sec ServerErrCode) Int() int

Int get code int from error code

func (ServerErrCode) String

func (sec ServerErrCode) String() string

String get error string from error code

Directories

Path Synopsis
v1
dcc
fb

Jump to

Keyboard shortcuts

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