photon

package module
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 2025 License: MIT Imports: 0 Imported by: 0

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 applications with clarity and flexibility.


✨ Features

  • Gateway: Seamlessly switch between HTTP and WebSocket backends .
  • 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 get github.com/smtdfc/photon-http-gateway
go install github.com/smtdfc/photon-cli

⚙️ Getting Started

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

In modules/hello/http.go:

package hello

import "github.com/smtdfc/photon/core"
import "github.com/smtdfc/photon-http-gateway"
import "github.com/smtdfc/photon-http-gateway/middlewares/cors"

var (
  ROUTE_PREFIX = ""
)

func initRoute(){
  logger := self().Logger
  gateway := core.ResolveGateway[*httpGateway.Gateway](self(),"http")
  http:= gateway.CreateScope(self(),ROUTE_PREFIX)
  http.SetLogger(logger)
  http.Use(cors.Middleware(cors.Config{}))
  
  http.Get(
    "/hello",
    func(ctx core.HttpContext){
      ctx.Text(200,"Hello world ")
    },
  )
}

In modules/hello/lifecycle.go:

package hello

// This function will be called when the module is initialized. 
func onModuleInit(){
  initRoute() // Call when module start
}

//This function will be called when the module starts. 
func onModuleStart(){}

Register the module in your app:

package app

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

func InitModule(app *core.App) {
    hello.Init(app)
}
4. Run the app
photon-cli dev

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

📜 License

Photon is licensed under the MIT License. © 2025 smtdfc

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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