Quick Start
Create and run a small Procyon HTTP application.
Introduction
Procyon is an application framework for Go. In this guide, you create a small HTTP controller, register it as a component, map a route, and let the runtime start the application.
If the package is not installed yet, add it first:
go mod init example.com/hello
go get -u codnect.io/procyon/...Create a controller
Create a component that owns the endpoint behavior:
package main
import (
"codnect.io/procyon/component"
"codnect.io/procyon/http"
)
type HelloController struct{}
func NewHelloController() *HelloController {
return &HelloController{}
}
func (h *HelloController) ConfigureEndpoints(endpoints http.Endpoints) {
endpoints.MapGet("/hello", http.Handle(h.sayHello))
}
func (h *HelloController) sayHello(ctx *http.Context) error {
_, err := ctx.Response().Writer().Write([]byte("Hello, World!"))
return err
}
func init() {
component.Register(NewHelloController)
}ConfigureEndpoints is called by the HTTP runtime. The controller maps
GET /hello to sayHello, and component.Register makes the controller part
of the application component graph.
Start the application
Create a small entrypoint and hand startup to Procyon:
package main
import (
"os"
"codnect.io/procyon"
)
func main() {
if err := procyon.Run(); err != nil {
os.Exit(1)
}
}procyon.Run() prepares configuration, creates the runtime context, loads
registered components, maps endpoints, and keeps the process running when a
server is available.
Run it
Run the application from your module:
go run .Then request the endpoint:
curl http://localhost:8080/helloWhat happened?
The quick start uses the same pieces as a larger application:
component.Registerregisters constructor-based components.http.EndpointConfigurerlets a component contribute routes.http.Endpointsmaps paths and methods to handlers.http.Contextgives the handler access to the request and response.procyon.Runcoordinates startup and shutdown.
Continue with What is Procyon? when you want the bigger runtime model, or HTTP docs when you want to build more routes.
