photon

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2025 License: MIT Imports: 2 Imported by: 2

README

Photon

Photon is a lightweight and extensible backend framework for Go. Built with a modular, adapter-based architecture, Photon enables developers to create robust HTTP and WebSocket applications with clarity and flexibility.


✨ Features

  • Modular Adapters: Seamlessly switch between HTTP and WebSocket backends (e.g., Echo, Melody).
  • Plug-and-Play Architecture: Easy integration of custom adapters.
  • Minimalistic Core: No hidden magic — full transparency and maintainability.

🚀 Installation

go get github.com/smtdfc/photon
go install github.com/smtdfc/photon-cli

⚙️ Getting Started

1. Create a new Echo-based Photon app
go mod init example.com/hello
photon gen app hello
2. Generate a module
photon gen module hello
3. Define your module routes

In internal/hello/init.go:

package hello

func (m *HelloModule) InitRoute() {
    m.Module.Route("GET", "/hello", m.Handler.Hello)
}

In internal/hello/handler.go:

package hello

import "github.com/smtdfc/photon"

type HelloModuleHandler struct{}

func (h *HelloModuleHandler) Hello(req photon.Request, res photon.Response) {
    res.JSON(200, map[string]any{
        "message": "Hello World 🚀",
    })
}

Register the module in your app:

package app

import (
    "github.com/smtdfc/photon"
    "example.com/hello/internal/hello"
)

func InitModule(app *photon.App) {
    hello.Init(app)
}
4. Run the app
go run .

Access it at: http://127.0.0.1:3000/hello


🔌 Custom Adapter Development

Photon adapters must implement the following interfaces:

BaseHTTPAdapter
type BaseHTTPAdapter interface {
    GetName() string
    Init() error
    Start() error
    Listen(port string) error
    UseSocket(path string, socketAdapter BaseSocketAdapter) error
    Route(method string, path string, handler RouteHandler)
}
BaseSocketAdapter
type BaseSocketAdapter interface {
    GetName() string
    Init() error
    Start() error
    On(event string, handler SocketEventHandler)
    Emit(event string, data []byte) error
    Stop() error
    HTTPHandler() func(http.ResponseWriter, *http.Request)
}

📆 Ecosystem


📜 License

Photon is licensed under the MIT License. © 2025 smtdfc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Inject added in v0.0.4

func Inject[T any](target Module, edge string) T

func InjectTo added in v0.0.4

func InjectTo(edge string, target Module, provider Provider)

Types

type App

type App struct {
	GlobalData map[string]any
	Logger     *Logger
}

func CreateApp added in v0.0.4

func CreateApp() *App

func (*App) Start

func (a *App) Start(port string) error

type Logger added in v0.0.4

type Logger struct {
	Target string
}

func CreateLogger added in v0.0.4

func CreateLogger(target string) *Logger

func (*Logger) Debug added in v0.0.4

func (l *Logger) Debug(msg string)

func (*Logger) Error added in v0.0.4

func (l *Logger) Error(msg string)

func (*Logger) Fatal added in v0.0.4

func (l *Logger) Fatal(msg string)

func (*Logger) Info added in v0.0.4

func (l *Logger) Info(msg string)

func (*Logger) Warn added in v0.0.4

func (l *Logger) Warn(msg string)

type Module

type Module struct {
	Name string
	// contains filtered or unexported fields
}

func (*Module) GetInject added in v0.0.4

func (m *Module) GetInject(edge string) any

func (*Module) GetProvide added in v0.0.4

func (m *Module) GetProvide() any

func (*Module) Inject added in v0.0.4

func (m *Module) Inject(edge string, provider Provider)

func (*Module) Provide added in v0.0.4

func (m *Module) Provide(value any)

type Provider added in v0.0.4

type Provider interface {
	GetProvide() any
}

Directories

Path Synopsis
cli module
cmd
photon module
core module
dix module
http-gateway module

Jump to

Keyboard shortcuts

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