dawn

package module
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2020 License: MIT Imports: 12 Imported by: 0

README

Dawn

`Dawn` is an opinionated `web` framework that provides rapid development capabilities. It provides basic services such as logging, configuration, `fiber` extension, `gorm` extension, and event system.

The core idea of ​​Dawn is modularity. High-level business modules can invoke low-level modules, such as databases and so on.

Each module needs to implement its own two core methods of Init and Boot, and then register it in Sloop. General business modules need to implement its Register Routes method to register routes and provide http services.

The modules should be based on the principle of not recreating the wheel, and directly provides the original structure and method of the dependent library.

The libraries currently used are

Notice

This project is still under development, please do not use it in a production environment.

Why dawn?

Tribute to the first episode of one piece romance dawn. Let us set sail towards romance with the sloop.

Documentation

Index

Constants

View Source
const Version = "0.3.6"

Version of current dawn package

Variables

This section is empty.

Functions

This section is empty.

Types

type Cleanup

type Cleanup func()

Cleanup is a function does cleanup works

type Module

type Module struct{}

Module is an empty struct implements Moduler interface and can be embedded into custom struct as a Moduler

func (Module) Boot

func (Module) Boot()

Boot boots the module.

func (Module) Init

func (Module) Init() Cleanup

Init does initialization works and should return a cleanup function.

func (Module) RegisterRoutes

func (Module) RegisterRoutes(fiber.Router)

RegisterRoutes add routes to fiber router

func (Module) String

func (Module) String() string

String indicates module's name

type Moduler

type Moduler interface {
	// Stringer indicates module's name
	fmt.Stringer

	// Init does initialization works and should return
	// a cleanup function.
	Init() Cleanup

	// Boot boots the module.
	Boot()

	// RegisterRoutes add routes to fiber router
	RegisterRoutes(fiber.Router)
}

Moduler is the interface that wraps the module's method.

type Option

type Option func(s *Sloop)

Option can be applied in server

func App

func App(app *fiber.App) Option

App option sets custom Fiber App to Sloop

func Modulers

func Modulers(mods ...Moduler) Option

Modulers option adds several Modulers to server

type Sloop

type Sloop struct {
	// contains filtered or unexported fields
}

Sloop denotes Dawn application

func Default

func Default(cfg ...fiber.Config) *Sloop

Default returns an Sloop instance with the - RequestID - Logger - Recovery - Pprof middleware already attached in default fiber app.

func New

func New(opts ...Option) *Sloop

New returns a new Sloop with options.

func (*Sloop) AddModulers

func (s *Sloop) AddModulers(m ...Moduler) *Sloop

AddModulers appends more Modulers

func (*Sloop) Cleanup

func (s *Sloop) Cleanup()

Cleanup releases resources

func (*Sloop) Router

func (s *Sloop) Router() fiber.Router

Router returns the server router

func (*Sloop) Run

func (s *Sloop) Run(addr string) error

Run runs a web server

func (*Sloop) RunTls

func (s *Sloop) RunTls(addr, certFile, keyFile string) error

RunTls runs a tls web server

func (*Sloop) Setup

func (s *Sloop) Setup() *Sloop

Setup initializes all modules and then boots them

func (*Sloop) Shutdown

func (s *Sloop) Shutdown() error

Shutdown gracefully shuts down the server without interrupting any active connections.

func (*Sloop) Watch

func (s *Sloop) Watch()

Watch listens to signal to exit

Directories

Path Synopsis
_examples
log
cmd
db
sql

Jump to

Keyboard shortcuts

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