-
Notifications
You must be signed in to change notification settings - Fork 3
/
ghp.go
53 lines (46 loc) · 1.43 KB
/
ghp.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package ghp
import (
// "net/url"
"net/http"
)
// StartServlet is called when a servlet is initialized.
//
type StartServlet = func(ServletContext)
// StopServlet is called just after the servlet was hot-reloaded;
// replaced by a newer instance.
//
// It is guaranteed that no other calls to this instance of the servlet
// will occur at or after the point in time when this function is called.
//
// The servlet should stop any running tasks and deallocate any persistent
// resources.
//
type StopServlet = func(ServletContext)
// ServeHTTP is called to serve a HTTP request.
// It's the servlet's full and lone responsibility to handle the request.
// This is essentially a go net/http.Handler function, so anything you'd do
// in a net/http.Handler function, you can do here.
//
type ServeHTTP = func(*Request, Response)
// ServletContext represents the servlet instance itself.
//
type ServletContext interface {
Name() string // servlet name
Version() string // instance version
}
// Request represents a HTTP request.
//
type Request http.Request
// Response represents a HTTP response.
// Implements io.Writable
// Implements http.ResponseWriter
//
type Response interface {
Header() http.Header
Write([]byte) (int, error)
WriteString(string) (int, error)
WriteHeader(statusCode int)
Print(a interface{}) (int, error)
Printf(format string, arg... interface{}) (int, error)
Flush() bool // returns true on success
}