This repository was archived by the owner on May 19, 2025. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathserver.go
More file actions
47 lines (41 loc) · 1.34 KB
/
server.go
File metadata and controls
47 lines (41 loc) · 1.34 KB
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
// Package server is the server package for Paymail
package server
import (
"fmt"
"net/http"
"strings"
"github.com/mrz1836/go-logger"
)
// CreateServer will create a basic Paymail Server
func CreateServer(c *Configuration) *http.Server {
return &http.Server{
Addr: fmt.Sprintf(":%d", c.Port), // Address to run the server on
Handler: Handlers(c), // Load all the routes
ReadHeaderTimeout: c.Timeout, // Basic default timeout for header read requests
ReadTimeout: c.Timeout, // Basic default timeout for read requests
WriteTimeout: c.Timeout, // Basic default timeout for write requests
}
}
// StartServer will run the Paymail server
func StartServer(srv *http.Server) {
logger.Data(2, logger.DEBUG, "starting go paymail server...", logger.MakeParameter("address", srv.Addr))
logger.Fatalln(srv.ListenAndServe())
}
// getHost tries its best to return the request host
func getHost(r *http.Request) string {
if r.URL.IsAbs() {
return removePort(r.Host)
}
if len(r.URL.Host) == 0 {
return removePort(r.Host)
}
return r.URL.Host
}
// removePort will attempt to remove the port if found
func removePort(host string) string {
// Slice off any port information.
if i := strings.Index(host, ":"); i != -1 {
host = host[:i]
}
return host
}