Documentation ¶
Index ¶
- func GetBool(r *http.Request, name string, value bool) bool
- func GetInt(r *http.Request, name string, value int) int
- func GetString(r *http.Request, name string, value string) string
- func Return(w http.ResponseWriter, code int, data interface{})
- type API
- type BanWatcher
- type EventData
- type EventSource
- type Server
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetBool ¶
GetBool search the boolean argument by given name from the URL and PostForm, if not exists, return the given value as default.
func GetInt ¶
GetInt search the integer argument by given name from the URL and PostForm, if not exists, return the given value as default.
func GetString ¶
GetString search the string argument by given name from the URL and PostForm, if not exists, return the given value as default.
func Return ¶
func Return(w http.ResponseWriter, code int, data interface{})
Return write response to w, code is the http code, data is the content will write into responseBody, can be string or []byte.
Types ¶
type API ¶
type API interface { // decode the data Decode([]byte) error // encode the data Encode() ([]byte, error) // the http route uri for this api URI() string // which watcher want to use WatcherName() string // the key used to watch, // eg. return '/lain/config/vip' for coreinfoWatcher, // return 'console' as appname for coreifnoWacher and podgroupWatcher Key(r *http.Request) (string, error) // create new api by data // return a new instance of API with real data in it // second boolean value represent if the data really having some changes Make(data map[string]interface{}) (API, bool, error) }
API is a common interface which a api instance must realize
type BanWatcher ¶
type BanWatcher interface {
BanWatch()
}
BanWatcher is a interface to ban watch feature. you can realize this interface if your do not want your api support watch request.
type EventData ¶
EventData is a type which can be send by SendEvent(), SendEvent() will call Encode() and then write result into connection.
type EventSource ¶
type EventSource struct {
// contains filtered or unexported fields
}
EventSource is a component which can hajick http connection and then send event to client.
func NewEventSource ¶
func NewEventSource(w http.ResponseWriter) (*EventSource, error)
NewEventSource create a new event source, event source will hijack w.conn; so you can not write anything to this responseWriter after calling this.
func (*EventSource) Close ¶
func (es *EventSource) Close()
Close the event source, this function also close the http connection.
func (*EventSource) CloseNotify ¶
func (es *EventSource) CloseNotify() <-chan bool
CloseNotify return a channel used to notify the connection's close event. the return channel will be closed when connection was closed, nothing send into it.
func (*EventSource) SendEvent ¶
func (es *EventSource) SendEvent(id uint64, event string, data interface{}) error
SendEvent send a event to client. data can be []byte, string or EventData. it should not contain '\n' in it, otherwize only the first line will be send. the given data can be string or []byte or EventData
type Server ¶
Server used by lainlet, based on martini
func New ¶
New create a http api server; ip is the server ip, it was used by some query; version is the lainlet version, used to return by `/version` api; st is the backend store, it must be valided, should not be a empty interface or a nil value. This function return error when fail to initialize some backend watcher.