Skip to content

go-srvc/mods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

58 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

codecov main

Modules for srvc

Each of the modules implements srvc.Module interface and can be used with srvc.Run.

Example

package main

import (
	"fmt"
	"net/http"
	"os"

	"github.com/go-srvc/mods/httpmod"
	"github.com/go-srvc/mods/logmod"
	"github.com/go-srvc/mods/metermod"
	"github.com/go-srvc/mods/sigmod"
	"github.com/go-srvc/mods/sqlxmod"
	"github.com/go-srvc/mods/tracemod"
	"github.com/go-srvc/srvc"
)

func main() {
	db := sqlxmod.New()
	srvc.RunAndExit(
		sigmod.New(os.Interrupt),
		logmod.New(),
		tracemod.New(),
		metermod.New(),
		db,
		httpmod.New(
			httpmod.WithHandler(
				handler(db),
			),
		),
	)
}

func handler(db *sqlxmod.DB) http.Handler {
	return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		if err := db.DB().PingContext(r.Context()); err != nil {
			http.Error(w, err.Error(), http.StatusInternalServerError)
			return
		}
		fmt.Fprint(w, "OK")
	})
}

Modules:

HTTP server module wrapping http.Server.

Wrapper for otel log provider.

Wrapper for otel metrics provider.

Signal handling module for graceful application shutdown.

SQL module wrapping sql.DB.

SQL module wrapping sqlx.DB.

Ticker module wrapping time.Ticker.

Wrapper for otel tracer provider.

About

Modules for srvc library

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors