Skip to content

hermesgen/hm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

hm

Go Reference codecov

A collection of Go primitives and utilities for Hermes organization projects. Provides common interfaces and helper functions for entity management, validation, and HTTP handling.

Installation

go get github.com/hermesgen/hm

Quick Start

package main

import (
	"context"
	"embed"
	"os"
	"os/signal"
	"syscall"
	"time"

	"github.com/hermesgen/hm"
)

const (
	name    = "myapp"
	version = "v1.0.0"
)

//go:embed assets
var assetsFS embed.FS

func main() {
	ctx := context.Background()
	log := hm.NewLogger("info")
	cfg := hm.LoadCfg("myapp", hm.Flags)

	params := hm.XParams{Cfg: cfg, Log: log}

	// Infrastructure
	queryManager := hm.NewQueryManager(assetsFS, "sqlite", params)
	templateManager := hm.NewTemplateManager(assetsFS, params)
	migrator := hm.NewMigrator(assetsFS, "sqlite", params)
	fileServer := hm.NewFileServer(assetsFS, params)
	fm := hm.NewFlashManager(params)

	// Application
	app := hm.NewApp("myapp", params)
	app.MountFileServer("/", fileServer)

	// API Router
	apiRouter := hm.NewAPIRouter("api-router", params)
	app.MountAPI("/api/v1", apiRouter)

	// Web Router
	webRouter := hm.NewWebRouter("web-router", params)
	app.MountWeb("/", webRouter)

	// Add dependencies
	app.Add(migrator, queryManager, templateManager, fileServer, fm)

	err := app.Setup(ctx)
	if err != nil {
		log.Errorf("Cannot setup app: %v", err)
		return
	}

	stop := make(chan os.Signal, 1)
	signal.Notify(stop, os.Interrupt, syscall.SIGTERM, syscall.SIGQUIT)

	go func() {
		err := app.Start(ctx)
		if err != nil {
			log.Errorf("Cannot start %s(%s): %v", name, version, err)
		}
	}()

	log.Infof("%s(%s) started successfully", name, version)

	<-stop

	log.Infof("Shutting down %s(%s)...", name, version)
	shutdownCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
	defer cancel()

	err = app.Stop(shutdownCtx)
	if err != nil {
		log.Errorf("Error during shutdown: %v", err)
	} else {
		log.Infof("%s(%s) stopped gracefully", name, version)
	}
}

Development

Running Tests

# Run all tests
make test

# Run tests with coverage
make coverage

# Run tests with HTML coverage report
make coverage-html

# Check if coverage meets 80% threshold
make coverage-check

Quality Checks

# Run all quality checks (format, vet, test, coverage, lint)
make check

# Run CI pipeline (strict)
make ci

About

Hermes Kit

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors