Documentation
¶
Overview ¶
Package mserver is a wrapper around `net/http` HTTP Server for Graceful shutdown of web server upon SIGINT SIGKILL signals sent to the application or Internal Errors of the web server. It also provides some useful crypto functions to calculate Hashes(Sha, Md5 etc.)
Index ¶
- Variables
- func BufToHexString(data *bytes.Buffer) string
- func Md5(data *bytes.Buffer) *bytes.Buffer
- func Sha1(data *bytes.Buffer) *bytes.Buffer
- func Sha224(data *bytes.Buffer) *bytes.Buffer
- func Sha256(data *bytes.Buffer) *bytes.Buffer
- func Sha384(data *bytes.Buffer) *bytes.Buffer
- func Sha512(data *bytes.Buffer) *bytes.Buffer
- func Sha512_224(data *bytes.Buffer) *bytes.Buffer
- func Sha512_256(data *bytes.Buffer) *bytes.Buffer
- type Mserver
Constants ¶
This section is empty.
Variables ¶
var ErrServerNotStarted = errors.New("Server Not Started Yet")
Server not started Error code
Functions ¶
func BufToHexString ¶
BufToHexString converts the bytes.Buffer into a Hexadecimal string
func Md5 ¶
Md5 function get the MD5 Hash from a given bytes.Buffer and returns the result also in bytes.Buffer
func Sha1 ¶
Sha1 function get the SHA1 Hash from a given bytes.Buffer and returns the result also in bytes.Buffer As per the FIPS 180-4 : When a message of any length less than 2^64 bits We need to use SHA-1, SHA-224 and SHA-256 That would be 2048 Petabytes
func Sha224 ¶
Sha224 function get the SHA2-224 Hash from a given bytes.Buffer and returns the result also in bytes.Buffer
func Sha256 ¶
Sha256 function get the SHA2-256 Hash from a given bytes.Buffer and returns the result also in bytes.Buffer
func Sha384 ¶
Sha384 function get the SHA2-384 Hash from a given bytes.Buffer and returns the result also in bytes.Buffer
func Sha512 ¶
Sha512 function get the SHA2-512 Hash from a given bytes.Buffer and returns the result also in bytes.Buffer
func Sha512_224 ¶
Sha512_224 function get the SHA2-512/224 Hash from a given bytes.Buffer and returns the result also in bytes.Buffer
Types ¶
type Mserver ¶
type Mserver struct { Server *http.Server // Instance of the Server ShutdownTimeout time.Duration // Timeout before a force shutdown is called Error error // Last error in operations of the Server // contains filtered or unexported fields }
Mserver or Managed Server is a derivation of the standard HTTP server Provided in Golang standard package `net/http`.
This type provides the facility to stop the HTTP server gracefully and automatically on 3 Events:
1. Ctrl + C is pressed or SIGINT is send to program
2. SIGKILL is send to program
3. Error occurs in Normal Server operation
func NewMserver ¶
NewMserver creates a default Instance of the `Mserver` type and then calls the `StartDefaultServer` to begin default server operation.
func (*Mserver) ForceStop ¶
func (p *Mserver) ForceStop()
ForceStop provides a forced way to terminate further processing by sending a false kill signal to a graseful shutdown running function
func (*Mserver) GracefulStop ¶
GracefulStop provides a way to stop the server properly with help of `context` package.
The `waitForInterrupt` parameter is used to Listen for SIGINT or SIGKILL sent to the program.
Additionally if an error was reported previous to the function call, it initiates the shutdown of the server. This is done using the member `Mserver.Error` which stores the Last error.
func (*Mserver) StartDefaultServer ¶
StartDefaultServer creates a `http.DefaultServeMux` adds it to `http.Server` along with the provided `addr` which is the server address.
The `timeout` is used as wait time before web server is terminated or stopped. It is bassically to force close the server in case it does not respond to a shutdown request. This feature uses the `context` package.
func (*Mserver) StartServer ¶
StartServer creates a server(`http.Server`) using the provided `http.ServeMux` setting it up with the provided `addr` as the server address.
The `mux` can be any type implementing `http.ServeMux` and also the `http.DefaultServeMux`.
The `timeout` is used as wait time before web server is terminated or stopped. It is bassically to force close the server in case it does not respond to a shutdown request. This feature uses the `context` package.