app

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2023 License: MIT Imports: 15 Imported by: 0

Documentation

Overview

Package app exposes a http server to run the API app.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Server

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

Server is a simple http app server. Simple, but extensible.

For a more capable wrapper (with trace & metrics exporters, graceful shutdown...), checkout github.com/casualjim/go-appserver or similar alternatives.

We can use this wrapper to initialize other components, e.g. auth middleware etc.

func NewServer

func NewServer(appName string, logger *zap.Logger, cfg *viper.Viper) *Server

NewServer builds a new instance of the API server.

There is a 2-stage warming-up: (i) Init() (ii) Start(). Stages are separated to be able to extend the capabilities with hot reload.

func (Server) App

func (r Server) App() chi.Router

func (Server) Config

func (r Server) Config() *viper.Viper

func (Server) DB

func (r Server) DB() *sqlx.DB

func (*Server) Init

func (s *Server) Init() error

Init warms up the server by preparing things such as database connection pools, dependent API clients, etc.

func (Server) Logger

func (r Server) Logger() log.Factory

func (Server) Repos

func (r Server) Repos() repos.Iface

func (*Server) Start

func (s *Server) Start() error

Start the API server.

This version starts an http server.

It can be easily extended to start multiple listeners and suppot multiple protocols (e.g. grpc, ...).

TODO(fredbi): security - https configuration

func (*Server) Stop

func (s *Server) Stop() error

Stop the API server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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