goNextService

package module
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 6 Imported by: 0

README

Service base

This repository contains base components for our backend services.

Usage

// Any http.Handler compatible struct
mux := http.NewServerMux()
// Create http component
http := application.NewHttpComponent(router)
// Compose new application
app := application.NewApplications(http)
// Run blocks until application exits
err :=  app.Run()
if err ! nil{
    return err
}

Structure

Each compoonent is composed of 3 functions, that will be invoked by the Application

  • Startup
  • Run
  • Close
Lifecycle
---
title: Lifecycle
---
stateDiagram-v2
    state "Application starting" as AS
    state "Application running" as AR
    state is_c_running_state <<choice>>
    state is_a_running_state <<choice>>
    
    [*] --> AS: Application.Run()
    AS --> Component
    state Component {
        [*] --> Starting: Component.Startup()
        Starting --> Running: Component.Run()
        Running --> is_c_running_state
        is_c_running_state --> Running
        is_c_running_state --> Closing: Error
        Closing --> Done: Component.Close()
    }
    AS --> AR: All components has started
    AR --> is_a_running_state
    is_a_running_state --> AR
    is_a_running_state --> Closing: Signal to shutdown
    Done --> [*]
TODO
  • Test
  • Replace zap with configurable logger
  • Move hardcoded strings into config
  • Document metricz and healthz components
  • Document how to create new components
  • Better documentation

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Application

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

func NewApplications

func NewApplications(components ...Component) *Application

func (*Application) AddComponent

func (app *Application) AddComponent(c Component)

func (*Application) Run

func (app *Application) Run() error

func (Application) WithLogger added in v0.1.4

func (app Application) WithLogger(logger Logger) Application

func (Application) WithTimeout

func (app Application) WithTimeout(timeout time.Duration) Application

type Component

type Component interface {
	// Synchronous startup, container runs this one by one
	Startup() error
	// Asynchronous run,  container runs this in parrallel
	// Has to block until it's done
	// When one of componenst exits this func, container will start shutting down
	Run() error
	// Cleanup function
	Close(ctx context.Context) error
}

type Logger added in v0.1.4

type Logger interface {
	Debugf(mgs string, params ...any)
	Infof(mgs string, params ...any)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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