status

package module
v0.1.22 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: MIT Imports: 7 Imported by: 1

README

GoREST Status Plugin

CI Go Report Card License

Status check endpoint plugin for GoREST framework.

Installation

go get github.com/nicolasbonnici/gorest-status

Development Environment

To set up your development environment:

make install

This will:

  • Install Go dependencies
  • Install development tools (golangci-lint)
  • Set up git hooks (pre-commit linting and tests)

Usage

import (
	"github.com/nicolasbonnici/gorest/pluginloader"
	statusplugin "github.com/nicolasbonnici/gorest-status"
)

func init() {
	pluginloader.RegisterPluginFactory("status", statusplugin.NewPlugin)
}
Configuration

Add to your gorest.yaml:

plugins:
  - name: status
    enabled: true
Advanced Configuration

You can customize the endpoint path using plugin configuration:

plugins:
  - name: status
    enabled: true
    config:
      endpoint: "health"  # Custom endpoint path (default: "status")

Configuration Parameters:

  • endpoint (string): Custom path for the health check endpoint. Default: "status"
    • Example: "health" creates endpoint at /health
    • Example: "api/status" creates endpoint at /api/status

Server Configuration:

The plugin automatically receives server configuration from GoREST v0.4.4+ for accurate URL logging:

  • server_scheme: Protocol (http/https) - Default: "http"
  • server_host: Hostname or IP address - Default: "localhost"
  • server_port: Port number - Default: 8000

These parameters are automatically injected by GoREST based on your gorest.yaml server configuration. The plugin uses these values to display the correct health check URL in startup logs.

Example server configuration in gorest.yaml:

server:
  scheme: https
  host: api.example.com
  port: 443

plugins:
  - name: status
    enabled: true
    config:
      endpoint: "health"

This will display: Health check available at https://api.example.com/health (ports 80 with http scheme and 443 with https scheme are omitted).

Features

  • Customizable status check endpoint (default: /status)
  • Database connectivity check
  • Returns HTTP 200 when healthy
  • Returns HTTP 503 when database is down
  • JSON response format
  • Startup logging with endpoint URL

Response Format

Healthy (database configured and up):

{
  "status": "healthy",
  "database": {
    "status": "up"
  }
}

Unhealthy (database down):

{
  "status": "unhealthy",
  "database": {
    "status": "down",
    "error": "connection failed"
  }
}

Database not configured:

{
  "status": "healthy",
  "database": {
    "status": "not_configured"
  }
}

Git Hooks

This directory contains git hooks for the GoREST plugin to maintain code quality.

Available Hooks
pre-commit

Runs before each commit to ensure code quality:

  • Linting: Runs make lint to check code style and potential issues
  • Tests: Runs make test to verify all tests pass
Installation
Automatic Installation

Run the install script from the project root:

./.githooks/install.sh
Manual Installation

Copy the hooks to your .git/hooks directory:

cp .githooks/pre-commit .git/hooks/pre-commit
chmod +x .git/hooks/pre-commit

License

MIT License - see LICENSE file for details

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPlugin

func NewPlugin() plugin.Plugin

NewPlugin creates a new instance with default settings

Types

type Plugin added in v0.1.7

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

Plugin provides a status check endpoint for health monitoring

func (*Plugin) Handler added in v0.1.7

func (p *Plugin) Handler() fiber.Handler

Handler returns a no-op middleware handler (status endpoint is registered via SetupEndpoints)

func (*Plugin) Initialize added in v0.1.7

func (p *Plugin) Initialize(config map[string]interface{}) error

Initialize configures the plugin with the provided configuration map

func (*Plugin) Name added in v0.1.7

func (p *Plugin) Name() string

Name returns the plugin identifier

func (*Plugin) SetupEndpoints added in v0.1.7

func (p *Plugin) SetupEndpoints(router fiber.Router) error

SetupEndpoints registers the status check HTTP endpoint

Jump to

Keyboard shortcuts

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