server

package
v0.0.0-...-55d7ca3 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Module = fx.Options(fx.Invoke(func(p params) error {
	httpServer := &http.Server{
		Addr:         string(p.Addr),
		WriteTimeout: 30 * time.Second,
		ReadTimeout:  30 * time.Second,
		IdleTimeout:  30 * time.Second,
		Handler:      http.TimeoutHandler(p.Router, 30*time.Second, "server timeout"),
	}
	log := p.Logger.Named("http-server")

	p.Lifecycle.Append(fx.Hook{
		OnStart: func(context.Context) error {
			go func() {
				log.Infow("starting http-server...", "addr", string(p.Addr))
				shutdownStatus := httpServer.ListenAndServe()
				log.Infow("http-server was started", "status", shutdownStatus)

				_ = p.Shutdowner.Shutdown()
			}()
			return nil
		},
		OnStop: func(ctx context.Context) error {
			log.Infow("http-server is stopping...")
			return httpServer.Shutdown(ctx)
		},
	})

	return nil
}))

Functions

This section is empty.

Types

type Addr

type Addr string

type Name

type Name string

Jump to

Keyboard shortcuts

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