server

package module
v1.4.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 23, 2016 License: MIT Imports: 9 Imported by: 53

README

server

A simple http server with logging and configs, using http.ListenAndServe

Usage
	// Setup server
	server, err := server.New()
	if err != nil {
		fmt.Printf("Error creating server %s", err)
		return
	}

	// Write to log 
	server.Logf("#info Starting server in %s mode on port %d", server.Mode(), server.Port())

	// Start the server
	err = server.Start()
	if err != nil {
		server.Fatalf("Error starting server %s", err)
	}

Documentation

Overview

Package server offers a simple server with logging and configs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Logger

type Logger interface {
	Printf(format string, args ...interface{})
}

Logger interface for a simple logger (the stdlib log pkg and the fragmenta log pkg conform)

type Server

type Server struct {
	// Our internal logger instance
	Logger Logger
	// contains filtered or unexported fields
}

Server holds the config and logger for the app

func New

func New() (*Server, error)

New creates a new server instance

func (*Server) Config

func (s *Server) Config(key string) string

Config returns a specific configuration value or "" if no value

func (*Server) ConfigBool

func (s *Server) ConfigBool(key string) bool

ConfigBool returns the current configuration value as bool (yes=true, no=false), or false if no value

func (*Server) ConfigInt

func (s *Server) ConfigInt(key string) int64

ConfigInt returns the current configuration value as int64, or 0 if no value

func (*Server) Configuration

func (s *Server) Configuration() map[string]string

Configuration returns the map of configuration keys to values

func (*Server) Fatal

func (s *Server) Fatal(format string)

Fatal logs the message, and then exits with status 1

func (*Server) Fatalf

func (s *Server) Fatalf(format string, v ...interface{})

Fatalf the message with the given arguments to our internal logger, and then exits with status 1

func (*Server) Log

func (s *Server) Log(message string)

Log logs the message to our internal logger

func (*Server) Logf

func (s *Server) Logf(format string, v ...interface{})

Logf logs the message with the given arguments to our internal logger

func (*Server) Mode

func (s *Server) Mode() string

Mode returns the mode (production or development)

func (*Server) Port

func (s *Server) Port() int

Port returns the port of the server

func (*Server) Production

func (s *Server) Production() bool

Production tells the caller if this server is in production mode or not?

func (*Server) Start

func (s *Server) Start() error

Start starts the http server on our given port

func (*Server) Timef

func (s *Server) Timef(format string, start time.Time, v ...interface{})

Timef logs a time since starting, when used with defer at the start of a function to time Usage: defer s.Timef("Completed %s in %s",time.Now(),args...)

Directories

Path Synopsis
Package log provides a simple file and console log
Package log provides a simple file and console log
Package schedule provides a simple way to schedule functions at a time or interval Package schedule provides a simple way to schedule functions at a time or interval
Package schedule provides a simple way to schedule functions at a time or interval Package schedule provides a simple way to schedule functions at a time or interval

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL