Documentation ¶
Index ¶
- Variables
- func AuthMiddleware(authFunc MiddlewareFunction) mux.MiddlewareFunc
- func BasePath(base, api string) string
- func CorsMiddleware(next http.Handler) http.Handler
- func FaviconHandler(w http.ResponseWriter, r *http.Request)
- func GetServer(serverConfig ServerConfiguration) *http.Server
- func HomeHandler(w http.ResponseWriter, r *http.Request)
- func InitLimiter(period string)
- func LetsEncryptServer(hosts ...string) *http.Server
- func LimitMiddleware(next http.Handler) http.Handler
- func LogRequest(w http.ResponseWriter, r *http.Request, start time.Time, cauth string, ...)
- func LoggingMiddleware(h http.Handler) http.Handler
- func ResponseMsg(w http.ResponseWriter, r *http.Request, msg, api string, code int)
- func SignUpHandler(w http.ResponseWriter, r *http.Request)
- func StartServer(serverConfig ServerConfiguration, handler http.Handler)
- func TlsServer(serverCrt, serverKey, rootCAs string, port, verbose int) *http.Server
- func ValidateMiddleware(validateFunc MiddlewareFunction) mux.MiddlewareFunc
- type HTTPRecord
- type LogRecord
- type LogWriter
- type MiddlewareFunction
- type RotateLogWriter
- type ServerConfiguration
- type ServerRouter
- type Templates
- type TmplRecord
Constants ¶
This section is empty.
Variables ¶
var BottomHTML string
BottomHTML represents bottom html content
var PrintLogRecord bool
PrintLogRecord controls if we'll print to stdout log record in JSON data format. This is useful in k8s setup when we can redirect logs to dedidcated file and at the same time print log record to stdout for scraping by monitoring/k8s systems
var TmplDir string
TmplDir defines location of templates
var TopHTML string
TopHTML represents top html content
var UTC bool
UTC flag represents UTC time zone for log messages
Functions ¶
func AuthMiddleware ¶
func AuthMiddleware(authFunc MiddlewareFunction) mux.MiddlewareFunc
AuthMiddleware provide auth/authz action for incoming HTTP requests. User should initialize it with MiddlewareFunction which accepts http Header and return the error
func CorsMiddleware ¶
Corsmiddleware provides CORS
func FaviconHandler ¶
func FaviconHandler(w http.ResponseWriter, r *http.Request)
FaviconHandler provides favicon icon file
func GetServer ¶
func GetServer(serverConfig ServerConfiguration) *http.Server
GetServer returns http.Server object for different configurations
func HomeHandler ¶
func HomeHandler(w http.ResponseWriter, r *http.Request)
HomeHandler handles home page requests
func InitLimiter ¶
func InitLimiter(period string)
InitLimiter initializes Limiter middleware pointer
func LetsEncryptServer ¶
LetsEncryptServer provides HTTPs server with Let's encrypt for given domain names (hosts)
func LimitMiddleware ¶
LimitMiddleware limits incoming requests
func LogRequest ¶
func LogRequest(w http.ResponseWriter, r *http.Request, start time.Time, cauth string, status *int, tstamp int64, bytesOut int64)
helper function to log every single user request, here we pass pointer to status code as it may change through the handler while we use defer logRequest
func LoggingMiddleware ¶
LoggingMiddleware provides logging middleware for HTTP requests https://arunvelsriram.dev/simple-golang-http-logging-middleware
func ResponseMsg ¶
ResponseMsg helper function to provide response to end-user ResponseMsg(w, r, fmt.Sprintf("%v", err), "VaultDeleteHandler", http.StatusBadRequest)
func SignUpHandler ¶
func SignUpHandler(w http.ResponseWriter, r *http.Request)
SignUpHandler handles sign-up page requests
func StartServer ¶
func StartServer(serverConfig ServerConfiguration, handler http.Handler)
StartServer starts web server with given http handler
func ValidateMiddleware ¶
func ValidateMiddleware(validateFunc MiddlewareFunction) mux.MiddlewareFunc
ValidateMiddleware provides validation action for incoming HTTP requests. User should initialize it with MiddlewareFunction which accepts http Header and return the error
Types ¶
type LogRecord ¶
type LogRecord struct { Method string `json:"method"` // http.Request HTTP method Host string `json:"hostname"` // hostname of the server URI string `json:"uri"` // http.RequestURI API string `json:"api"` // http service API being used System string `json:"system"` // cmsweb service name ClientIP string `json:"clientip"` // client IP address BytesSend int64 `json:"bytes_send"` // number of bytes send with HTTP request BytesReceived int64 `json:"bytes_received"` // number of bytes received with HTTP request Proto string `json:"proto"` // http.Request protocol Status int64 `json:"status"` // http.Request status code ContentLength int64 `json:"content_length"` // http.Request content-length AuthProto string `json:"auth_proto"` // authentication protocol AuthCert string `json:"auth_cert"` // auth certificate, user DN LoginName string `json:"login_name"` // login name, user DN Auth string `json:"auth"` // auth method Cipher string `json:"cipher"` // TLS cipher name Referer string `json:"referer"` // http referer UserAgent string `json:"user_agent"` // http user-agent field XForwardedHost string `json:"x_forwarded_host"` // http.Request X-Forwarded-Host XForwardedFor string `json:"x_forwarded_for"` // http.Request X-Forwarded-For RemoteAddr string `json:"remote_addr"` // http.Request remote address ResponseStatus string `json:"response_status"` // http.Response status ResponseTime float64 `json:"response_time"` // http response time RequestTime float64 `json:"request_time"` // http request time Timestamp int64 `json:"timestamp"` // record timestamp RecTimestamp int64 `json:"rec_timestamp"` // timestamp for backward compatibility with apache RecDate string `json:"rec_date"` // timestamp for backward compatibility with apache }
LogRecord represents HTTP log record
type MiddlewareFunction ¶
MiddlewareFunction defines common function to be used by mux middleware For examaple, we can provide Authentication or Validator functions to corresponding middleware
type RotateLogWriter ¶
type RotateLogWriter struct {
RotateLogs *rotatelogs.RotateLogs
}
RotateLogWriter represents rorate log writer
type ServerConfiguration ¶
type ServerConfiguration struct { Port int `json:"port"` // server port number Base string `json:"base"` // base URL Verbose int `json:"verbose"` // verbose output ServerCrt string `json:"serverCrt"` // path to server crt file ServerKey string `json:"serverKey"` // path to server key file RootCA string `json:"rootCA"` // RootCA file CSRFKey string `json:"csrfKey"` // CSRF 32-byte-long-auth-key Production bool `json:"production"` // production server or not LimiterPeriod string `json:"rate"` // limiter rate value LogFile string `json:"log_file"` // server log file LetsEncrypt bool `json:"lets_encrypt"` // start LetsEncrypt HTTPs server DomainNames []string `json:"domain_names"` // list of domain names to use StaticDir string `json:"static"` // location of static files Templates string `json:"templates"` // location of server templates }
ServerConfiguration stores server configuration parameters
func NewServerConfig ¶
func NewServerConfig() ServerConfiguration
NewServerConfig creates new ServerConfigruation with some default parameters
func ParseServerConfig ¶
func ParseServerConfig(configFile string) (ServerConfiguration, error)
ParseServerConfig parses server configuration