hippo

package module
v2.0.2 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2020 License: MIT Imports: 10 Imported by: 4

README

hippo

The hippo is an easy, fast, lightweight server engine which supports gracefully shutdown.

Build Status Go Report Card

Hippo

Simple server struct

type SimpleServer struct {
	hippo.Launcher // DO NOT REMOVE; links servers and engines each other.
}

func (s *SimpleServer) Start() error {
	return nil
}

func (s *SimpleServer) Stop() error {
	return nil
}

Run

Simple
engine := hippo.NewEngine(&SimpleServer{}, nil)
if err := engine.Start(); err != nil {
    panic(err)
}
Debug
config := &hippo.Config{
    Debug: true,
}
engine := hippo.NewEngine(&SimpleServer{}, config)
if err := engine.Start(); err != nil {
    panic(err)
}
Log to the file
config := &hippo.Config{
    Debug:  true,
    LogDir: "/var/log/",
}
engine := hippo.NewEngine(&SimpleServer{}, config)
if err := engine.Start(); err != nil {
    panic(err)
}

Gracefully shutdown

type NormalServer struct {
	hippo.Launcher // DO NOT REMOVE
}

func (s *NormalServer) Start() error {
	for {
		s.Log.Info("server is working on it")

		// return errors.New("intentional error")

		select {
		case <-s.Done: // for gracefully shutdown
			return nil
		case <-time.After(2 * time.Second):
		}
	}
}

func (s *NormalServer) Stop() error {
	return nil
}

console output

DEBU[2020-02-12T10:23:00+09:00] logger has been initialized                  
DEBU[2020-02-12T10:23:00+09:00] engine has been started                      
DEBU[2020-02-12T10:23:00+09:00] server has been started                      
INFO[2020-02-12T10:23:00+09:00] server is working on it                      
INFO[2020-02-12T10:23:02+09:00] server is working on it                      
INFO[2020-02-12T10:23:03+09:00] received signal, shutting down..             
DEBU[2020-02-12T10:23:03+09:00] server canceled; no longer works             
DEBU[2020-02-12T10:23:03+09:00] server has been stopped                      
DEBU[2020-02-12T10:23:03+09:00] engine has been stopped 

Documentation

Overview

Hippo is an easy, fast, lightweight server framework.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name        string
	DisplayName string
	Description string
	Version     string
	LogDir      string
	Debug       bool
	Trace       bool
	Logger      *log.Logger
}

Hippo configuration struct

type Engine

type Engine struct {
	Config *Config
	// contains filtered or unexported fields
}

Engine supports engine framework.

func NewEngine

func NewEngine(server Server, config *Config) *Engine

NewEngine allocates a new server to engine.

func (*Engine) GetWorkingDir

func (e *Engine) GetWorkingDir() string

func (*Engine) Start

func (e *Engine) Start() error

Start starts server and opens error channel.

type Launcher

type Launcher struct {
	Engine *Engine
	Log    *logrus.Logger
	Done   <-chan struct{}
}

type Server

type Server interface {
	Start() error
	Stop() error
	// contains filtered or unexported methods
}

Server is the interface that configures the server

Directories

Path Synopsis
cmd
1-simple command

Jump to

Keyboard shortcuts

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