Cloudy is a lightweight, flexible web framework for Go that emphasizes simplicity and productivity. It provides a clean architecture for building web applications with features like routing, sessions, middleware, and more.
- Simple and intuitive API
- Built-in session management
- Flash message support
- Middleware pipeline
- Controller-based architecture
- Easy routing with method mapping
go get github.com/CloudyKit/cloudyBelow is a basic example of how to set up a Cloudy web application:
myapp/
├── app/
│ └── app.go
├── cmd/
│ └── server.go
└── controllers/
└── home.go
package main
import"github.com/CloudyKit/cloudy-example/app"funcmain() {
app.Kernel.RunServer(":8888")
}package app
import (
"github.com/CloudyKit/cloudy""github.com/CloudyKit/cloudy-example/controllers""github.com/CloudyKit/cloudy/flash""github.com/CloudyKit/cloudy/session"
)
varKernel=cloudy.NewKernel()
funcinit() {
// Register componentsKernel.AddComponents(
&session.Component{
Manager: session.DefaultManager,
CookieOptions: session.DefaultCookieOptions,
},
&flash.Component{},
)
// Register controllersKernel.AddControllers(
&controllers.Home{},
)
// Add middlewareKernel.AddMiddlewareFunc(func(ctx*cloudy.Context) {
ctx.Response.Header().Set("X-Cloudy", "CloudyKit")
})
}package controllers
import (
"github.com/CloudyKit/cloudy""github.com/CloudyKit/cloudy/session"
)
typeHomestruct {
Context*cloudy.ContextSessionData*session.Session
}
// Mx maps HTTP methods to controller actionsfunc (h*Home) Mx(mx*cloudy.Mapper) { mx.BindAction("GET", "/", "Index")
}
// Index handles the root pathfunc (h*Home) Index() {
counter, _:=h.SessionData.Get("counter").(int)
_, _=h.Context.PrintfWriteStringfWriteString("Counter: %d", counter)
counter++deferh.SessionData.Set("counter", counter)
}The Kernel is the central component that manages the application lifecycle. It handles routing, middleware execution, and component initialization.
Controllers handle incoming requests and produce responses. In Cloudy, controllers are Go structs with methods that correspond to HTTP endpoints.
Middleware functions can be added to the request processing pipeline to handle cross-cutting concerns like authentication, logging, etc.
Components provide additional functionality like sessions and flash messages. They can be easily added to the application's kernel.
The Mapper binds HTTP methods and paths to controller methods, making routing simple and intuitive.
To run the example application:
go run cmd/server.goThen visit http://localhost:8888 in your browser. You should see a counter that increments on each page refresh, demonstrating the session functionality.
[MIT License]
Contributions are welcome! Please feel free to submit a Pull Request.'