/
cyclops.go
42 lines (35 loc) · 1.09 KB
/
cyclops.go
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
// cyclops is a minimal web framework
package cyclops
import (
"fmt"
"github.com/flannel-dev-lab/cyclops/input"
"log"
"net/http"
)
const banner = `
______ ______/ /__ ___ ___
/ __/ // / __/ / _ \/ _ \(_-<
\__/\_, /\__/_/\___/ .__/___/
/___/ /_/
https://github.com/flannel-dev-lab/cyclops
`
// StartServer starts a simple http server
func StartServer(address string, handler http.Handler) {
fmt.Print(banner)
if err := http.ListenAndServe(address, handler); err != http.ErrServerClosed {
// Error starting or closing listener:
log.Fatalf("HTTP server ListenAndServe: %v", err)
}
}
// StartTLSServer starts a TLS server with provided TLS cert and key files
func StartTLSServer(address string, handler http.Handler, certFile, keyFile string) {
fmt.Print(banner)
if err := http.ListenAndServeTLS(address, certFile, keyFile, handler); err != http.ErrServerClosed {
// Error starting or closing listener:
log.Fatalf("HTTPS server ListenAndServe: %v", err)
}
}
// Param - Get a url parameter by name
func Param(r *http.Request, name string) string {
return input.Query(name, r)
}