-
Notifications
You must be signed in to change notification settings - Fork 0
Documentation
Package web-byte implements a web server utility.
The definition of the types in the package, and the respective functions can be found below.
Overview
type ByteServer
func MakeByteServer(servingPort uint32, serverHandler http.Handler) (*ByteServer, error)
func (bs *ByteServer) Serve() error
func (bs *ByteServer) AddHandler(pattern string, handleFunc func(http.ResponseWriter, *http.Request))
type ByteServer struct {
// Handlers holds a mapping of respective patterns and functions
// used by the server.
Handlers map[string]func(w http.ResponseWriter, _ *http.Request)
// ServingPort specifies the port on which the server will serve.
ServingPort uint32
// Handler specifies the main handler for the server.
Handler http.Handler
}ByteServer implements a web server.
This type makes use of net/http to implement a simple template-like server for users to define and flesh out according to their requirements.
func MakeByteServer(servingPort uint32, serverHandler http.Handler) (*ByteServer, error)MakeByteServer() creates a new instance of ByteServer and returns a pointer to it. The function takes the following arguments:
-
servingPortType: uint32
servingPortspecifies the port on which to serve. -
serverHandlerType: http.Handler
serverHandlerspecifies the main handler for the server.
func (bs *ByteServer) Serve() errorServe starts the serving process of the server.
func (bs *ByteServer) AddHandler(pattern string, handleFunc func(http.ResponseWriter, *http.Request))
func (bs *ByteServer) AddHandler(pattern string, handleFunc func(http.ResponseWriter, *http.Request))AddHandler adds a handler function to the server.
It takes the following arguments:
-
patternType: string
is used to register the handle function for a given pattern. -
handleFuncType:func(http.ResponseWriter, *http.Request)
defines a handler function for the server to use for the respectivepattern