http

package
v0.0.0-...-fee78ac Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GET    = "GET"    // http get method
	PUT    = "PUT"    // http put method
	POST   = "POST"   // http post method
	PATCH  = "PATCH"  // http patch method
	DELETE = "DELETE" // http delete method

	TCP_DEFAULT_TIME_OUT = 3 * time.Minute // default timeout
)
View Source
const UNIX_SOCKET_DEFAULT_TIME_OUT = 30 * time.Second

Variables

This section is empty.

Functions

func IsSocketFile

func IsSocketFile(path string) bool

func NewClient

func NewClient() *resty.Client

func NewSocketListener

func NewSocketListener(path string) (*net.UnixListener, error)

func NewTcpListener

func NewTcpListener(addr string) (*net.TCPListener, error)

func SendDeleteRequest

func SendDeleteRequest(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) error

SendDeleteRequest will send http delete request to the agent. If ret is not nil, it should be a pointer.

func SendDeleteRequestAndReturnResponse

func SendDeleteRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) (*resty.Response, error)

SendDeleteRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendDeleteRequestViaUnixSocket

func SendDeleteRequestViaUnixSocket(socketPath string, uri string, param, ret interface{}) error

func SendGetRequest

func SendGetRequest(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) error

SendGetRequest will send http get request to the agent. If ret is not nil, it should be a pointer.

func SendGetRequestAndReturnResponse

func SendGetRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) (*resty.Response, error)

SendGetRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendGetRequestViaUnixSocket

func SendGetRequestViaUnixSocket(socketPath string, uri string, param, ret interface{}) error

func SendPatchRequest

func SendPatchRequest(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) error

SendPatchRequest will send http patch request to the agent. If ret is not nil, it should be a pointer.

func SendPatchRequestAndReturnResponse

func SendPatchRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) (*resty.Response, error)

SendPatchRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendPatchRequestViaUnixSocket

func SendPatchRequestViaUnixSocket(socketPath string, uri string, param, ret interface{}) error

func SendPostRequest

func SendPostRequest(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) error

SendPostRequest will send http post request to the agent. If ret is not nil, it should be a pointer.

func SendPostRequestAndReturnResponse

func SendPostRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) (*resty.Response, error)

SendPostRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendPostRequestViaUnixSocket

func SendPostRequestViaUnixSocket(socketPath string, uri string, param, ret interface{}) error

func SendPutRequest

func SendPutRequest(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) error

SendPutRequest will send http put request to the agent. If ret is not nil, it should be a pointer.

func SendPutRequestAndReturnResponse

func SendPutRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, param, ret interface{}) (*resty.Response, error)

SendPutRequestAndReturnResponse will return http response and error. If ret is not nil, it should be a pointer.

func SendPutRequestViaUnixSocket

func SendPutRequestViaUnixSocket(socketPath string, uri string, param, ret interface{}) error

func SendRequestAndBuildReturn

func SendRequestAndBuildReturn(agentInfo meta.AgentInfoInterface, uri string, method string, param, ret interface{}, headers map[string]string) error

func SendRequestAndBuildReturnViaUnixSocket

func SendRequestAndBuildReturnViaUnixSocket(socketPath, uri, method string, param, ret interface{}, headers map[string]string) error

func SendRequestAndReturnResponse

func SendRequestAndReturnResponse(agentInfo meta.AgentInfoInterface, uri string, method string, param, ret interface{}, headers map[string]string) (*resty.Response, error)

SendRequestAndReturnResponse will return http response and error.

func SendRequestAndReturnResponseViaUnixSocket

func SendRequestAndReturnResponseViaUnixSocket(socketPath string, uri string, method string, param, ret interface{}, headers map[string]string) (*resty.Response, error)

func SocketCanConnect

func SocketCanConnect(network, addr string, timeout time.Duration) bool

func SocketIsActive

func SocketIsActive(socketPath string) bool

func UploadFileViaUnixSocket

func UploadFileViaUnixSocket(socketPath, uri, filePath string, ret interface{}) (err error)

Types

type AgentStatus

type AgentStatus struct {
	Agent meta.AgentInfoWithIdentity `json:"agent"`

	State            int32  `json:"state"`   // service state
	Version          string `json:"version"` // service version
	Pid              int    `json:"pid"`     // service pid
	StartAt          int64  `json:"startAt"` // timestamp when service started
	Port             int    `json:"port"`    // Ports process occupied ports
	OBState          int    `json:"obState"`
	UnderMaintenance bool   `json:"underMaintenance"`
}

Status info api response

type ApiError

type ApiError struct {
	Code      int           `json:"code"`                // Error code
	Message   string        `json:"message"`             // Error message
	SubErrors []interface{} `json:"subErrors,omitempty"` // Sub errors
}

ApiError is the api error struct of ocsagent.

func (ApiError) String

func (a ApiError) String() string

type ApiFieldError

type ApiFieldError struct {
	Tag     string `json:"tag"`
	Field   string `json:"field"`
	Message string `json:"message"`
}

ApiFieldError is the api field error struct of ocsagent.

type ApiUnknownError

type ApiUnknownError struct {
	Error error `json:"error"`
}

type IterableData

type IterableData struct {
	Contents interface{} `json:"contents"`
}

type Listener

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

func NewListener

func NewListener() *Listener

func (*Listener) AddHandler

func (l *Listener) AddHandler(path string, h http.Handler)

type OcsAgentResponse

type OcsAgentResponse struct {
	Successful bool        `json:"successful"`      // Whether request successful or not
	Timestamp  time.Time   `json:"timestamp"`       // Request handling timestamp (server time)
	Duration   int64       `json:"duration"`        // Request handling time cost (ms)
	Status     int         `json:"status"`          // HTTP status code
	TraceId    string      `json:"traceId"`         // Request trace ID, contained in server logs
	Data       interface{} `json:"data,omitempty"`  // Data payload when response is successful
	Error      *ApiError   `json:"error,omitempty"` // Error payload when response is failed
}

OcsAgentResponse is the response struct of ocsagent.

func BuildNoContentResponse

func BuildNoContentResponse() OcsAgentResponse

func BuildResponse

func BuildResponse(data interface{}, err error) OcsAgentResponse

func NewSubErrorsResponse

func NewSubErrorsResponse(subErrors []interface{}) OcsAgentResponse

type OcsAgentResponseData

type OcsAgentResponseData struct {
	TaskId int
}

OcsAgentResponseData is the response data struct of ocsagent.

type State

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

func NewState

func NewState(state int32) *State

func (*State) CasState

func (s *State) CasState(old, new int32) bool

func (*State) GetState

func (s *State) GetState() int32

func (*State) IsRunning

func (s *State) IsRunning() bool

func (*State) IsStarting

func (s *State) IsStarting() bool

func (*State) IsStopped

func (s *State) IsStopped() bool

func (*State) IsStopping

func (s *State) IsStopping() bool

func (*State) SetState

func (s *State) SetState(state int32)

Jump to

Keyboard shortcuts

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