app

package
v1.5.7 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: MIT Imports: 7 Imported by: 4

README

app

Start and stop services gracefully, using errgroup to ensure that multiple services are started properly at the same time.


Example of use

import "github.com/zhufuyi/sponge/pkg/app"

func main() {
    initApp()
    servers := registerServers()
    closes := registerCloses(servers)

    a := app.New(servers, closes)
    a.Run()
}

func initApp() {
    // get configuration

    // initializing log

    // initializing database

    // ......
}

func registerServers() []app.IServer {
    var servers []app.IServer

    // creating http service
    servers = append(servers, server.NewHTTPServer(

    ))

    // creating grpc service
    servers = append(servers, server.NewGRPCServer(

    ))

    // ......

    return servers
}

func registerCloses(servers []app.IServer) []app.Close {
    var closes []app.Close

    // close server
    for _, server := range servers {
        closes = append(closes, server.Stop)
    }

    // close other resource
    closes = append(closes, func() error {

    })

    // ......

    return closes
}

Documentation

Overview

Package app is starting and stopping services gracefully, using golang.org/x/sync/errgroup to ensure that multiple services are started properly at the same time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type App

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

App servers

func New

func New(servers []IServer, closes []Close) *App

New create an app

func (*App) Run

func (a *App) Run()

Run servers

type Close

type Close func() error

Close app close

type IServer

type IServer interface {
	Start() error
	Stop() error
	String() string
}

IServer server interface

Jump to

Keyboard shortcuts

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