Documentation
¶
Index ¶
- Constants
- type Config
- type Event
- type FileUpload
- type Handler
- type Request
- type Response
- type Service
- func (s *Service) AddListener(l func(event int, ctx interface{}))
- func (s *Service) AddMiddleware(m middleware)
- func (s *Service) Init(cfg service.Config, c service.Container) (bool, error)
- func (s *Service) Serve() error
- func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)
- func (s *Service) Stop()
- type Uploads
- type UploadsConfig
- type Worker
- type WorkerList
Constants ¶
const ( // EventResponse thrown after the request been processed. See Event as payload. EventResponse = iota + 500 // EventError thrown on any non job error provided by road runner server. EventError )
const ( // There is no error, the file uploaded with success. UploadErrorOK = 0 // No file was uploaded. UploadErrorNoFile = 4 // Missing a temporary folder. UploadErrorNoTmpDir = 5 // Failed to write file to disk. UploadErrorCantWrite = 6 // Forbid file extension. UploadErrorExtension = 7 )
const ID = "http"
ID contains default svc name.
const MaxLevel = 127
MaxLevel defines maximum tree depth for incoming request data and files.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // Enable enables http svc. Enable bool // Address and port to handle as http server. Address string // MaxRequest specified max size for payload body in megabytes, set 0 to unlimited. MaxRequest int64 // Uploads configures uploads configuration. Uploads *UploadsConfig // Workers configures roadrunner server and worker pool. Workers *roadrunner.ServerConfig }
Configures RoadRunner HTTP server.
type Event ¶
type Event struct { // Method of the request. Method string // Uri requested by the client. Uri string // Status is response status. Status int // Associated error, if any. Error error }
Event represents singular http response event.
type FileUpload ¶
type FileUpload struct { // ID contains filename specified by the client. Name string `json:"name"` // Mime contains mime-type provided by the client. Mime string `json:"mime"` // Size of the uploaded file. Size int64 `json:"size"` // Error indicates file upload error (if any). See http://php.net/manual/en/features.file-upload.errors.php Error int `json:"error"` // TempFilename points to temporary file location. TempFilename string `json:"tmpName"` // contains filtered or unexported fields }
FileUpload represents singular file NewUpload.
func NewUpload ¶
func NewUpload(f *multipart.FileHeader) *FileUpload
NewUpload wraps net/http upload into PRS-7 compatible structure.
func (*FileUpload) Open ¶
func (f *FileUpload) Open(cfg *UploadsConfig) error
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler serves http connections to underlying PHP application using PSR-7 protocol. Context will include request headers, parsed files and query, payload will include parsed form dataTree (if any).
type Request ¶
type Request struct { // Protocol includes HTTP protocol version. Protocol string `json:"protocol"` // Method contains name of HTTP method used for the request. Method string `json:"method"` // Uri contains full request Uri with scheme and query. Uri string `json:"uri"` // Headers contains list of request headers. Headers http.Header `json:"headers"` // Cookies contains list of request cookies. Cookies map[string]string `json:"cookies"` // RawQuery contains non parsed query string (to be parsed on php end). RawQuery string `json:"rawQuery"` // Parsed indicates that request body has been parsed on RR end. Parsed bool `json:"parsed"` // Uploads contains list of uploaded files, their names, sized and associations with temporary files. Uploads *Uploads `json:"uploads"` // contains filtered or unexported fields }
Request maps net/http requests to PSR7 compatible structure and managed state of temporary uploaded files.
func NewRequest ¶
func NewRequest(r *http.Request, cfg *UploadsConfig) (req *Request, err error)
NewRequest creates new PSR7 compatible request using net/http request.
type Response ¶
type Response struct { // Status contains response status. Status int `json:"status"` // Headers contains list of response headers. Headers map[string][]string `json:"headers"` // contains filtered or unexported fields }
Response handles PSR7 response logic.
func NewResponse ¶
func NewResponse(p *roadrunner.Payload) (*Response, error)
NewResponse creates new response based on given roadrunner payload.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service manages rr, http servers.
func (*Service) AddListener ¶
AddListener attaches server event watcher.
func (*Service) AddMiddleware ¶
func (s *Service) AddMiddleware(m middleware)
func (*Service) Init ¶
Init must return configure svc and return true if svc hasStatus enabled. Must return error in case of misconfiguration. Services must not be used without proper configuration pushed first.
type Uploads ¶
type Uploads struct {
// contains filtered or unexported fields
}
tree manages uploaded files tree and temporary files.
func (*Uploads) MarshalJSON ¶
MarshalJSON marshal tree tree into JSON.
type UploadsConfig ¶
type UploadsConfig struct { // Dir contains name of directory to control access to. Dir string // Forbid specifies list of file extensions which are forbidden for access. // Example: .php, .exe, .bat, .htaccess and etc. Forbid []string }
UploadsConfig describes file location and controls access to them.
func (*UploadsConfig) Forbids ¶
func (cfg *UploadsConfig) Forbids(filename string) bool
Forbid must return true if file extension is not allowed for the upload.
func (*UploadsConfig) TmpDir ¶
func (cfg *UploadsConfig) TmpDir() string
TmpDir returns temporary directory.
type Worker ¶
type Worker struct { // Pid contains process id. Pid int `json:"pid"` // Status of the worker. Status string `json:"status"` // Number of worker executions. NumJobs int64 `json:"numExecs"` // Created is unix nano timestamp of worker creation time. Created int64 `json:"created"` }
Worker provides information about specific worker.
type WorkerList ¶
type WorkerList struct { // Workers is list of workers. Workers []Worker `json:"workers"` }
WorkerList contains list of workers.