Documentation ¶
Overview ¶
Package goserv is a simple web application server bootstrap. It provides a common base for those wishing to focus on their application rather than on setting up flags, configuration files or logging. go-serv also comes with a simple status system for those who wish to expose structures via HTTP(s) for monitoring.
Index ¶
- Constants
- Variables
- func BackgroundRunHttp(server *http.Server, conf *BaseConfiguration) chan error
- func BackgroundRunHttps(server *http.Server, conf *BaseConfiguration) chan error
- func FuncHandler(callable Callable, pretty bool) http.HandlerFunc
- func LogAccess(handler http.Handler) http.Handler
- func NewServer(conf *BaseConfiguration) http.Server
- func RestrictByIP(handler http.HandlerFunc, allowedIps []string) http.HandlerFunc
- func RunHttpAndHttps(server *http.Server, conf *BaseConfiguration) error
- func StructHandler(item interface{}, pretty bool) http.HandlerFunc
- type BaseConfiguration
- type Callable
- type Status
- Bugs
Constants ¶
const VERSION = "0.0.0"
Version of the library
Variables ¶
var ( // Package level logger Logger logrus.Logger // Logger used with http.Server. This is an instance of Logger.Writer() ServerErrorLogger log.Logger )
Functions ¶
func BackgroundRunHttp ¶
func BackgroundRunHttp(server *http.Server, conf *BaseConfiguration) chan error
BackgroundRunHttp runs an http server in a goroutine. Returns a send-only channel to watch for errors.
func BackgroundRunHttps ¶
func BackgroundRunHttps(server *http.Server, conf *BaseConfiguration) chan error
BackgroundRunHttps runs an https server in a goroutine. Returns a send-only channel to watch for errors.
func FuncHandler ¶
func FuncHandler(callable Callable, pretty bool) http.HandlerFunc
FuncHandler takes a Callable and bool to note if the results should be pretty and passes the resulting interface go StatusHandler.StructHandler
func NewServer ¶
func NewServer(conf *BaseConfiguration) http.Server
NewServer creates a new http.Server instance based off the BaseConfiguration. NewServer also handles reading the TOML configuration file and providing/reading the command line flags. Because of this NewServer should always be called after all flags have been defined.
func RestrictByIP ¶
func RestrictByIP(handler http.HandlerFunc, allowedIps []string) http.HandlerFunc
RestrictByIP restricts access to a handler by IP
func RunHttpAndHttps ¶
func RunHttpAndHttps(server *http.Server, conf *BaseConfiguration) error
Runs both Http and Https servers in their own goroutines. If one server exists the channels are closed and execution returns to the main goroutine.
func StructHandler ¶
func StructHandler(item interface{}, pretty bool) http.HandlerFunc
StructHandler takes an interface and bool to note if the results should be pretty and turns it into Status output in JSON
Types ¶
type BaseConfiguration ¶
type BaseConfiguration struct { BindAddress string BindPort int ReadTimeout time.Duration WriteTimeout time.Duration MaxHeaderBytes int LogLevel string LogFile string BindHttpsPort int CertFile string KeyFile string }
BaseConfiguration structure which can be filled out via defaults passed via flags, a configuration file or via the defaults set by the programmer (in that order of precedence)
Notes ¶
Bugs ¶
This needs work!!!
Directories ¶
Path | Synopsis |
---|---|
Godeps
|
|
_workspace/src/github.com/ogier/pflag
pflag is a drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags.
|
pflag is a drop-in replacement for Go's flag package, implementing POSIX/GNU-style --flags. |
A simple example using the Gorilla toolkit http://www.gorillatoolkit.org/
|
A simple example using the Gorilla toolkit http://www.gorillatoolkit.org/ |