server

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2019 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeResponse

func EncodeResponse(rw http.ResponseWriter, statusCode int, data interface{}) error

EncodeResponse encodes response in json.

func HandleErrorResponse

func HandleErrorResponse(w http.ResponseWriter, err error)

HandleErrorResponse handles err from daemon side and constructs response for client side.

Types

type Handler

type Handler func(ctx context.Context, rw http.ResponseWriter, req *http.Request) error

Handler is the http request handler.

type HandlerSpec

type HandlerSpec struct {
	Method      string
	Path        string
	HandlerFunc Handler
}

HandlerSpec is used to describe a HTTP API.

func NewHandlerSpec

func NewHandlerSpec(method, path string, handler Handler) *HandlerSpec

NewHandlerSpec constructs a brand new HandlerSpec.

type PullPieceTaskResponseContinueData added in v0.4.0

type PullPieceTaskResponseContinueData struct {
	Range     string `json:"range"`
	PieceNum  int    `json:"pieceNum"`
	PieceSize int32  `json:"pieceSize"`
	PieceMd5  string `json:"pieceMd5"`
	Cid       string `json:"cid"`
	PeerIP    string `json:"peerIp"`
	PeerPort  int    `json:"peerPort"`
	Path      string `json:"path"`
	DownLink  int    `json:"downLink"`
}

PullPieceTaskResponseContinueData is the data when successfully pulling piece task and the task is continuing.

type RegisterResponseData added in v0.4.0

type RegisterResponseData struct {
	TaskID     string `json:"taskId"`
	FileLength int64  `json:"fileLength"`
	PieceSize  int32  `json:"pieceSize"`
}

RegisterResponseData is the data when registering supernode successfully.

type ResultInfo added in v0.4.0

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

ResultInfo identify a struct that will returned to the client.

func NewResultInfo added in v0.4.0

func NewResultInfo(code int, msg string, data interface{}) ResultInfo

NewResultInfo returns a new ResultInfo.

func NewResultInfoWithCode added in v0.4.0

func NewResultInfoWithCode(code int) ResultInfo

NewResultInfoWithCode returns a new ResultInfo with code and it will get the default msg corresponding to the code as the value of ResultInfo.msg.

func NewResultInfoWithCodeData added in v0.4.0

func NewResultInfoWithCodeData(code int, data interface{}) ResultInfo

NewResultInfoWithCodeData returns a new ResultInfo with code and specified data.

func NewResultInfoWithCodeError added in v0.4.0

func NewResultInfoWithCodeError(code int, err error) ResultInfo

NewResultInfoWithCodeError returns a new ResultInfo with code and error. And it will get the err.Error() as the value of ResultInfo.msg.

func NewResultInfoWithCodeMsg added in v0.4.0

func NewResultInfoWithCodeMsg(code int, msg string) ResultInfo

NewResultInfoWithCodeMsg returns a new ResultInfo with code and specified msg.

func NewResultInfoWithError added in v0.4.0

func NewResultInfoWithError(err error) ResultInfo

NewResultInfoWithError returns a new ResultInfo with error only. And it will fill the result code according to the type of error.

func (ResultInfo) Error added in v0.4.0

func (r ResultInfo) Error() string

func (ResultInfo) SuccessCode added in v0.4.0

func (r ResultInfo) SuccessCode() bool

SuccessCode return whether the code equals SuccessCode.

type Server

type Server struct {
	Config       *config.Config
	PeerMgr      mgr.PeerMgr
	TaskMgr      mgr.TaskMgr
	DfgetTaskMgr mgr.DfgetTaskMgr
	ProgressMgr  mgr.ProgressMgr
}

Server is server instance.

func New

func New(cfg *config.Config) (*Server, error)

New creates a brand new server instance.

func (*Server) Start

func (s *Server) Start() error

Start runs

Jump to

Keyboard shortcuts

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