photon

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 0 Imported by: 0

README

Photon

Release CI codecov Coverage Lint Security Go Version License

Photon is a lightweight Go service toolkit for building production backends without rebuilding the same infrastructure plumbing in every service.

It gives teams a common foundation for HTTP and gRPC services, configuration, logging, telemetry, storage clients, cloud integrations, middleware, background workers, caching, and resilience utilities. The goal is not to hide Go behind a heavy framework. The goal is to keep normal Go code simple, observable, and consistent across services.

Photon Logo

What Photon Is Good For

  • Standardizing how Go services start, validate config, expose APIs, shut down, and emit telemetry.
  • Reusing proven wrappers for storage, cache, cloud, notification, auth, and session concerns.
  • Building services that need request middleware, retries, rate limits, background workers, and operational guardrails.
  • Keeping business logic free from repeated setup code while still allowing direct use of normal Go libraries.

Capability Map

Area What is included
HTTP Chi routing, configurable server startup, middleware, CORS, compression, timeout handling, recovery, request IDs, heartbeat, graceful shutdown hooks
gRPC Server and client wrappers, unary interceptors, logging, recovery, retries, health checks, TLS support
Config Koanf-backed loading, file/raw-byte sources, validation, default delimiter handling, optional watcher integration, non-fatal LoadE()
Observability Zerolog-backed logging, OpenTelemetry traces, metrics, logs, request context propagation
Storage MySQL, PostgreSQL, MongoDB, Elasticsearch, Aerospike, Redis, Memcached, and in-process FlashDB
Caching Provider-agnostic cache wrappers over Aerospike, Redis, Memcached, and FlashDB
Cloud Provider interfaces with AWS implementations for S3, SQS, SNS, AppConfig, SES, and Rekognition
Coordination Redis-backed locks, Redis-backed rate limiting, Consul service discovery, AppConfig watchers, retry with exponential backoff
Auth and Session JWT, OIDC, secure session management, Redis and memory-backed session stores
Workers Worker contracts, overseer lifecycle, restart policy, hooks, status snapshots
Notifications Slack, Teams, and SQS-backed notification publishing with validation, FIFO dedupe support, and audit hooks
Utilities REST helpers, CLI formatting, file system helpers, i18n data, encoding helpers, common data structures, type utilities

Install

Photon targets modern Go and currently declares:

go 1.27.1

Install it with:

go get github.com/cshekharsharma/photon

If the repository is private, configure GOPRIVATE for your environment before running go get.

go env -w GOPRIVATE=github.com/cshekharsharma/*

Quick Start

package main

import (
	"net/http"
	"time"

	"github.com/cshekharsharma/photon/core/router"
	server "github.com/cshekharsharma/photon/server/http"
)

func main() {
	server.StartHttpServer(&server.ServerConfig{
		ServerPort:    8080,
		ReadTimeout:   5 * time.Second,
		WriteTimeout:  10 * time.Second,
		IdleTimeout:   120 * time.Second,
		RouteProvider: router.RouterCHI,
		HttpRoutes: []*server.HttpRoute{
			{
				UrlRoute:      "/health",
				RequestMethod: http.MethodGet,
				HttpHandler: func(w http.ResponseWriter, r *http.Request) {
					w.WriteHeader(http.StatusOK)
				},
			},
		},
	})
}

For more examples, see docs/examples.

License

Photon is released under the Apache License 2.0.

Production Defaults

Photon is designed around explicit validation and safe defaults:

  • Config, HTTP server, Mongo, Postgres, notifier, and worker options validate early.
  • Default HTTP timeouts are applied when unset.
  • CORS rejects wildcard origins when credentials are enabled.
  • Mongo and Postgres wrappers avoid mutating caller-owned config while normalizing defaults.
  • Worker overseer supports context shutdown, bounded restart policy, lifecycle hooks, and status snapshots.
  • Notification publishing supports validation, audit hooks, and FIFO dedupe when the queue client supports it.

See Production Readiness for the release checklist.

Development

make tools
make configure
make test
make testcoverage

Useful checks before a release:

go test ./...
go vet ./...
staticcheck ./...
golangci-lint run ./...
govulncheck ./...
go test -race ./cloud ./cloud/providers ./cloud/service/aws ./core/logger ./telemetry ./coordination/network/discovery ./coordination/network/watcher ./middleware ./server/grpc/server ./server/http ./storage/aerospike ./storage/memcached ./storage/elasticsearch ./storage/mongo ./storage/mysql ./storage/redis ./utils/rest ./notifier/notifyrclient ./workers

Contributing

Contributions should be small, tested, and easy to review.

  • Branch from main.
  • Keep public APIs backward-compatible unless the change is intentionally breaking.
  • Add focused tests for new behavior and failure paths.
  • Run formatting, linting, tests, race tests where relevant, and vulnerability checks.
  • Update docs when behavior, configuration, or operational expectations change.

Security

Please do not open public issues for suspected vulnerabilities. Follow the process in SECURITY.md.

Documentation

Index

Constants

View Source
const (
	BuildVersion         string = "v1.0.0"
	MajorBuildVersion    int64  = 1
	MinorBuildVersion    int64  = 0
	SubminorBuildVersion int64  = 0
)

Variables

This section is empty.

Functions

This section is empty.

Types

This section is empty.

Directories

Path Synopsis
Package cloud provides abstractions and utilities to interact with cloud service providers, allowing easy switching and management of different cloud services based on configuration.
Package cloud provides abstractions and utilities to interact with cloud service providers, allowing easy switching and management of different cloud services based on configuration.
contract
PublishSubscribeInterface is a common interface that has to be implemented by all cloud vendor specific implementions (ie AWS, Azure, GCP).
PublishSubscribeInterface is a common interface that has to be implemented by all cloud vendor specific implementions (ie AWS, Azure, GCP).
entity/messagequeue
Package messagequeue provides structures and tools for interacting with a message queue system.
Package messagequeue provides structures and tools for interacting with a message queue system.
entity/objectstorage
Package objectstorage provides structures for interacting with an S3-compatible storage system.
Package objectstorage provides structures for interacting with an S3-compatible storage system.
entity/pubsub
Package pubsub provides structures for publishing messages to topics and managing topic attributes in a messaging system.
Package pubsub provides structures for publishing messages to topics and managing topic attributes in a messaging system.
entity/visualanalysis
Package visualanalysis provides cloud-agnostic inputs for image analysis.
Package visualanalysis provides cloud-agnostic inputs for image analysis.
providers
Package providers contains functionality for managing and interfacing with various AWS services.
Package providers contains functionality for managing and interfacing with various AWS services.
coordination
backoff
Package backoff provides a configurable, production-grade exponential backoff implementation with support for jitter, selective retries, per-attempt timeout, metrics hooks, and pluggable strategies.
Package backoff provides a configurable, production-grade exponential backoff implementation with support for jitter, selective retries, per-attempt timeout, metrics hooks, and pluggable strategies.
concurrency/lock
Package concurrency provides primitives to manage distributed concurrency patterns such as distributed locks.
Package concurrency provides primitives to manage distributed concurrency patterns such as distributed locks.
concurrency/ratelimiter
Package ratelimiter provides a pluggable interface and implementations for rate limiting strategies, including Redis-backed token bucket limiters.
Package ratelimiter provides a pluggable interface and implementations for rate limiting strategies, including Redis-backed token bucket limiters.
network/discovery
Package discovery provides a pluggable interface and Consul-based implementation for service discovery and registration in distributed systems.
Package discovery provides a pluggable interface and Consul-based implementation for service discovery and registration in distributed systems.
core
auth/jwt
Package jwt provides an easy to use capability to work with JWT auth mechanism.
Package jwt provides an easy to use capability to work with JWT auth mechanism.
Package notifier provides a unified interface for sending messages to different notification platforms such as Slack, Microsoft Teams, etc.
Package notifier provides a unified interface for sending messages to different notification platforms such as Slack, Microsoft Teams, etc.
server
grpc/client
Package grpc provides a production-grade gRPC client wrapper with support for TLS, retry, backoff, interceptors, load balancing, and testability.
Package grpc provides a production-grade gRPC client wrapper with support for TLS, retry, backoff, interceptors, load balancing, and testability.
http
Package http provides functionalities to configure, run, and manage an HTTP server, including middleware support, API route handling, background workers, and graceful shutdown.
Package http provides functionalities to configure, run, and manage an HTTP server, including middleware support, API route handling, background workers, and graceful shutdown.
storage
aerospike
Package aerospikeclient provides a high-level wrapper around the Aerospike Go client.
Package aerospikeclient provides a high-level wrapper around the Aerospike Go client.
elasticsearch
Package elastic provides functionality for establishing connections to Elasticsearch v8 clusters using the official Go client library "github.com/elastic/go-elasticsearch/v8".
Package elastic provides functionality for establishing connections to Elasticsearch v8 clusters using the official Go client library "github.com/elastic/go-elasticsearch/v8".
memcached
Package memcached provides functionality for establishing connections to Memcached servers using the gomemcache package "github.com/bradfitz/gomemcache/memcache".
Package memcached provides functionality for establishing connections to Memcached servers using the gomemcache package "github.com/bradfitz/gomemcache/memcache".
mysql
Package mysql provides utilities for establishing and managing connections to MySQL databases.
Package mysql provides utilities for establishing and managing connections to MySQL databases.
redis
Package redis provides functionality for establishing connections to Redis servers using the go-redis package "github.com/redis/go-redis/v9".
Package redis provides functionality for establishing connections to Redis servers using the go-redis package "github.com/redis/go-redis/v9".
cli
Package ansi allows for advanced terminal text manipulation.
Package ansi allows for advanced terminal text manipulation.
encoding
html_utils.go
html_utils.go
i18n
Package i18n provides a foundational implementation of a translation service using the Go x/text package.
Package i18n provides a foundational implementation of a translation service using the Go x/text package.
rest
Package rest provides the HTTP and REST related utilities for the application.
Package rest provides the HTTP and REST related utilities for the application.
rest/apiresponse
Package apiresponse contains all the data models that are expected to be used by the application for core workflows.
Package apiresponse contains all the data models that are expected to be used by the application for core workflows.
rest/httpstub
Package httpstub provides a mechanism to create and manage HTTP stubs for testing, development, and other scenarios where controlling outgoing HTTP responses is beneficial.
Package httpstub provides a mechanism to create and manage HTTP stubs for testing, development, and other scenarios where controlling outgoing HTTP responses is beneficial.
stdlib
LRU provides a fast, production‑grade Least Recently Used cache implementation.
LRU provides a fast, production‑grade Least Recently Used cache implementation.
Package contract keeps all the interfaces required for background workers.
Package contract keeps all the interfaces required for background workers.

Jump to

Keyboard shortcuts

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