srv

package
Version: v0.0.0-...-2c4df64 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2018 License: LGPL-3.0 Imports: 20 Imported by: 0

README

srv

a http service warpper with grollia mux

Documentation

Index

Constants

View Source
const (
	MIME_DEFAULT     = "application/octet-stream"
	MIME_OCTETSTREAM = MIME_DEFAULT
	MIME_GZIP        = "application/gzip"
	MIME_SEVENZ      = "application/x-7z-compressed"
	MIME_ZIP         = "application/zip"
	MIME_PDF         = "application/pdf"
	MIME_XLSX        = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
	MIME_DOCX        = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
	MIME_PPTX        = "application/vnd.openxmlformats-officedocument.presentationml.presentation"
	MIME_EPUB        = "application/epub+zip"
	MIME_JAR         = "application/jar"
	MIME_APK         = "application/vnd.android.package-archive"
	MIME_DOC         = "application/msword"
	MIME_PPT         = "application/vnd.ms-powerpoint"
	MIME_XLS         = "application/vnd.ms-excel"
	MIME_PS          = "application/postscript"
	MIME_PSD         = "application/x-photoshop"
	MIME_OGG         = "application/ogg"
	MIME_TXT         = "text/plain"
	MIME_JSON        = "application/json"
	MIME_HTML        = "text/html; charset=utf-8"
	MIME_PHP         = "text/x-php; charset=utf-8"
	MIME_RTF         = "text/rtf"
	MIME_JS          = "application/javascript"
	MIME_LUA         = "text/x-lua"
	MIME_PERL        = "text/x-perl"
	MIME_PYTHON      = "application/x-python"
	MIME_SVG         = "image/svg+xml"
	MIME_X3D         = "model/x3d+xml"
	MIME_KML         = "application/vnd.google-earth.kml+xml"
	MIME_COLLADA     = "model/vnd.collada+xml"
	MIME_GML         = "application/gml+xml"
	MIME_GPX         = "application/gpx+xml"
	MIME_PNG         = "image/png"
	MIME_JPG         = "image/jpeg"
	MIME_GIF         = "image/gif"
	MIME_WEBP        = "image/webp"
	MIME_TIFF        = "image/tiff"
	MIME_BMP         = "image/bmp"
	MIME_ICO         = "image/x-icon"
	MIME_MP3         = "audio/mpeg"
	MIME_FLAC        = "audio/flac"
	MIME_MIDI        = "audio/midi"
	MIME_APE         = "audio/ape"
	MIME_MUSEPACK    = "audio/musepack"
	MIME_WAV         = "audio/wav"
	MIME_AIFF        = "audio/aiff"
	MIME_AU          = "audio/basic"
	MIME_AMR         = "audio/amr"
	MIME_MP4         = "video/mp4"
	MIME_WEBM        = "video/webm"
	MIME_MPEG        = "video/mpeg"
	MIME_QUICKTIME   = "video/quicktime"
	MIME_THREEGP     = "video/3gp"
	MIME_AVI         = "video/x-msvideo"
	MIME_FLV         = "video/x-flv"
	MIME_MKV         = "video/x-matroska"
)
View Source
const (
	HEAD_Access_Control_Allow_Credentials    = "Access-Control-Allow-Credentials"
	HEAD_Access_Control_Allow_Headers        = "Access-Control-Allow-Headers"
	HEAD_Access_Control_Allow_Methods        = "Access-Control-Allow-Methods"
	HEAD_Access_Control_Allow_Origin         = "Access-Control-Allow-Origin"
	HEAD_Access_Control_Expose_Headers       = "Access-Control-Expose-Headers"
	HEAD_Access_Control_Max_Age              = "Access-Control-Max-Age"
	HEAD_Accept_Ranges                       = "Accept-Ranges"
	HEAD_Age                                 = "Age"
	HEAD_Allow                               = "Allow"
	HEAD_Alternate_Protocol                  = "Alternate-Protocol"
	HEAD_Cache_Control                       = "Cache-Control"
	HEAD_Client_Date                         = "Client-Date"
	HEAD_Client_Peer                         = "Client-Peer"
	HEAD_Client_Response_Num                 = "Client-Response-Num"
	HEAD_Connection                          = "Connection"
	HEAD_Content_Disposition                 = "Content-Disposition"
	HEAD_Content_Encoding                    = "Content-Encoding"
	HEAD_Content_Language                    = "Content-Language"
	HEAD_Content_Length                      = "Content-Length"
	HEAD_Content_Location                    = "Content-Location"
	HEAD_Content_MD5                         = "Content-MD5"
	HEAD_Content_Range                       = "Content-Range"
	HEAD_Content_Security_Policy             = "Content-Security-Policy"
	HEAD_X_Content_Security_Policy           = "X-Content-Security-Policy"
	HEAD_X_WebKit_CSP                        = "X-WebKit-CSP"
	HEAD_Content_Security_Policy_Report_Only = "Content-Security-Policy-Report-Only"
	HEAD_Content_Type                        = "Content-Type"
	HEAD_Date                                = "Date"
	HEAD_ETag                                = "ETag"
	HEAD_Expires                             = "Expires"
	HEAD_HTTP                                = "HTTP"
	HEAD_Keep_Alive                          = "Keep-Alive"
	HEAD_Last_Modified                       = "Last-Modified"
	HEAD_Link                                = "Link"
	HEAD_Location                            = "Location"
	HEAD_P3P                                 = "P3P"
	HEAD_Pragma                              = "Pragma"
	HEAD_Proxy_Authenticate                  = "Proxy-Authenticate"
	HEAD_Proxy_Connection                    = "Proxy-Connection"
	HEAD_Refresh                             = "Refresh"
	HEAD_Retry_After                         = "Retry-After"
	HEAD_Server                              = "Server"
	HEAD_Set_Cookie                          = "Set-Cookie"
	HEAD_Status                              = "Status"
	HEAD_Strict_Transport_Security           = "Strict-Transport-Security"
	HEAD_Timing_Allow_Origin                 = "Timing-Allow-Origin"
	HEAD_Trailer                             = "Trailer"
	HEAD_Transfer_Encoding                   = "Transfer-Encoding"
	HEAD_Upgrade                             = "Upgrade"
	HEAD_Vary                                = "Vary"
	HEAD_Via                                 = "Via"
	HEAD_Warning                             = "Warning"
	HEAD_WWW_Authenticate                    = "WWW-Authenticate"
	HEAD_X_Aspnet_Version                    = "X-Aspnet-Version"
	HEAD_X_Content_Type_Options              = "X-Content-Type-Options"
	HEAD_X_Frame_Options                     = "X-Frame-Options"
	HEAD_X_Permitted_Cross_Domain_Policies   = "X-Permitted-Cross-Domain-Policies"
	HEAD_X_Pingback                          = "X-Pingback"
	HEAD_X_Powered_By                        = "X-Powered-By"
	HEAD_X_Robots_Tag                        = "X-Robots-Tag"
	HEAD_X_UA_Compatible                     = "X-UA-Compatible"
	HEAD_X_XSS_Protection                    = "X-XSS-Protection"
)
View Source
const (
	CHARSET_UTF8 = `; charset=utf-8`
)

Variables

View Source
var (
	Mux    *mux2.Router
	Server *http.Server
)
View Source
var (
	ErrNoCallback = errors.New("No Callback ")
)

Functions

func DisableService

func DisableService(name string) bool

func DumpMux

func DumpMux() []string

func EnableService

func EnableService(name string) bool

func GetMessageId

func GetMessageId() string

func HasEnableService

func HasEnableService(name string) bool

func HasService

func HasService(name string) bool

func IsRunning

func IsRunning() bool

func ListenAndServe

func ListenAndServe(addr string)

func NewMiddleWare

func NewMiddleWare(fun mux2.MiddlewareFunc)

func NewResourceService

func NewResourceService(path string, handlerFunc http.Handler)

func NewResourceServiceDir

func NewResourceServiceDir(path, prefix, rootDir string, gzip bool, level int)

func NewServiceHandler

func NewServiceHandler(name string, path string, handlerFunc http.Handler)

func RegisterService

func RegisterService(service Service)

func ServiceStatus

func ServiceStatus(name string) int

func ServicesName

func ServicesName() (keys []string)

func ServicesStatus

func ServicesStatus() (ser map[string]bool)

func SetLogger

func SetLogger(logger Logger)

func Shutdown

func Shutdown() error

func WaitOsShutdown

func WaitOsShutdown(timeout time.Duration)

func WriteGabs

func WriteGabs(w http.ResponseWriter, mime string, status int, obj *gabs.Container)

func WriteGabsJson

func WriteGabsJson(w http.ResponseWriter, obj *gabs.Container)

func WriteJson

func WriteJson(w http.ResponseWriter, status int, obj interface{})

func WriteJsonError

func WriteJsonError(w http.ResponseWriter, status int, er error, humanMessage string)

func WsGabsCommander

func WsGabsCommander(commander func(conn *WsConnJson, msgType int, id string, msg *gabs.Container) error) func(conn *WsConnJson, err error, messageType int, message io.Reader) error

Types

type CODEC

type CODEC int
const (
	NULL CODEC = iota
	JSON
	MSGPK
	BINC
	CBOR
)

func (CODEC) Handler

func (e CODEC) Handler() codec.Handle

func (CODEC) String

func (e CODEC) String() string

type Logger

type Logger interface {
	CurrentLevel() int
	Fatalln(args ...interface{})
	Fatalf(format string, args ...interface{})
	Errorln(args ...interface{})
	Errorf(format string, args ...interface{})
	Warnln(args ...interface{})
	Warnf(format string, args ...interface{})
	Infoln(args ...interface{})
	Infof(format string, args ...interface{})
	Debugln(args ...interface{})
	Debugf(format string, args ...interface{})
	Traceln(args ...interface{})
	Tracef(format string, args ...interface{})
}

type Service

type Service interface {
	Name() string
	ServeHTTP(http.ResponseWriter, *http.Request)
	Disable()
	Enable()
	Status() bool
	Register(*mux2.Router)
}

type ServiceFunc

type ServiceFunc struct {
	Handler http.HandlerFunc
	// contains filtered or unexported fields
}

func NewService

func NewService(name string, path string, handlerFunc http.HandlerFunc) *ServiceFunc

func NewWebsocketService

func NewWebsocketService(name string, path string, handler WsHandlerFunction, readBufferSize, writeBufferSize int) *ServiceFunc

func (*ServiceFunc) Disable

func (s *ServiceFunc) Disable()

func (*ServiceFunc) Enable

func (s *ServiceFunc) Enable()

func (ServiceFunc) Name

func (s ServiceFunc) Name() string

func (ServiceFunc) Register

func (s ServiceFunc) Register(r *mux2.Router)

func (ServiceFunc) ServeHTTP

func (s ServiceFunc) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (ServiceFunc) Status

func (s ServiceFunc) Status() bool

type WsCallback

type WsCallback func(conn *WsConnJson, msg *gabs.Container) error

type WsConnCodec

type WsConnCodec struct {
	*websocket.Conn
	// contains filtered or unexported fields
}

func (WsConnCodec) WriteError

func (this WsConnCodec) WriteError(data error) error

func (WsConnCodec) WriteErrorFrame

func (this WsConnCodec) WriteErrorFrame(id string, data error) error

func (WsConnCodec) WriteFrame

func (this WsConnCodec) WriteFrame(id string, msg *gabs.Container) error

func (WsConnCodec) WriteFrameCallback

func (this WsConnCodec) WriteFrameCallback(id string, msg *gabs.Container, callback WsCallback) error

func (WsConnCodec) WriteRaw

func (this WsConnCodec) WriteRaw(data []byte, mtype int) error

type WsConnJson

type WsConnJson struct {
	*websocket.Conn
	// contains filtered or unexported fields
}

func NewWsConnJson

func NewWsConnJson(ws *websocket.Conn) *WsConnJson

func (WsConnJson) GetConn

func (this WsConnJson) GetConn() *websocket.Conn

func (WsConnJson) HandleCallback

func (this WsConnJson) HandleCallback(msg *gabs.Container) error

func (WsConnJson) Send

func (this WsConnJson) Send(msg *gabs.Container) error

func (WsConnJson) SendCallback

func (this WsConnJson) SendCallback(msg *gabs.Container, callback WsCallback) error

func (WsConnJson) SendError

func (this WsConnJson) SendError(err error) error

func (WsConnJson) SendErrorResponse

func (this WsConnJson) SendErrorResponse(id string, err error) error

func (WsConnJson) SendRaw

func (this WsConnJson) SendRaw(msg *gabs.Container) error

func (WsConnJson) SendResponse

func (this WsConnJson) SendResponse(id string, msg *gabs.Container) error

func (WsConnJson) SendResponseDone

func (this WsConnJson) SendResponseDone(id string, msg *gabs.Container) error

func (WsConnJson) SendResponseSuccess

func (this WsConnJson) SendResponseSuccess(id string) error

func (WsConnJson) WriteError

func (this WsConnJson) WriteError(data error) error

func (WsConnJson) WriteErrorFrame

func (this WsConnJson) WriteErrorFrame(id string, data error) error

func (WsConnJson) WriteFrame

func (this WsConnJson) WriteFrame(id string, msg *gabs.Container) (er error)

func (WsConnJson) WriteFrameCallback

func (this WsConnJson) WriteFrameCallback(id string, msg *gabs.Container, callback WsCallback) error

func (WsConnJson) WriteRaw

func (this WsConnJson) WriteRaw(data []byte, mtype int) error

type WsHandlerFunction

type WsHandlerFunction func(conn *WsConnJson, err error, messageType int, message io.Reader) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL