A Golang framework for web development that keeps your web applications and services responsive with its fast and lightweight design.
- Routing
- Route groups
- Static files
- Simple and elegant API
- Middleware support
Make sure you have Go installed on your machine. Then run the following command:
Initialize your project (Learn). Then install Pulse with the go get command:
go get github.com/gopulse/pulse
This test was performed by Go Web.
package main
import (
"github.com/gopulse/pulse"
)
func main() {
app := pulse.New()
router := pulse.NewRouter()
app.Router = router
router.Get("/", func(c *pulse.Context) error {
c.String("Hello, World!")
return nil
})
app.Run(":3000")
}
- Routing
Supports GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, CONNECT, TRACE
package main
import (
"github.com/gopulse/pulse"
)
func main() {
app := pulse.New()
router := pulse.NewRouter()
// GET /hello
router.Get("/", func(c *pulse.Context) error {
c.String("Hello, World!")
return nil
})
// GET /hello/:name
router.Get("/profile/:id", func(c *pulse.Context) error {
c.String("Profile: " + c.Param("id"))
return nil
})
// GET /user/
router.Get("/user/*", func(c *pulse.Context) error {
c.String("Hello, World!")
return nil
})
app.Router = router
app.Run(":3000")
}
- Route groups
Supports GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, CONNECT, TRACE
package main
import (
"github.com/gopulse/pulse"
)
func main() {
app := pulse.New()
router := pulse.NewRouter()
api := &pulse.Group{
prefix: "/api",
router: router,
}
v1 := api.Group("/v1")
v1.GET("/users", func(ctx *Context) error {
ctx.String("users")
return nil
})
app.Router = router
app.Run(":3000")
}
- Static files
package main
import (
"github.com/gopulse/pulse"
"time"
)
func main() {
app := pulse.New()
router := pulse.NewRouter()
// Static files (./static) with cache duration 24 hours
router.Static("/", "./static", &pulse.Static{
Compress: true,
ByteRange: false,
IndexName: "index.html",
CacheDuration: 24 * time.Hour,
})
app.Router = router
app.Run(":3000")
}
- Middleware
package main
import (
"github.com/gopulse/pulse"
)
func main() {
app := pulse.New()
router := pulse.NewRouter()
router.Get("/profile/:name", func(ctx *pulse.Context) error {
if ctx.Param("name") != "test" {
ctx.Abort()
ctx.Status(404)
return nil
}
ctx.String("hello")
ctx.Next()
return nil
})
app.Router = router
app.Run(":3000")
}
- CORS Middleware: Enable cross-origin resource sharing (CORS) with various options.
package main
import (
"github.com/gopulse/pulse"
)
func main() {
app := pulse.New()
router := pulse.NewRouter()
router.Get("/", func(ctx *pulse.Context) error {
return nil
})
router.Use("GET", pulse.CORSMiddleware())
app.Router = router
app.Run(":3000")
}
- Logger Middleware: Log every request with configurable options. (Coming soon)
- Encrypt Cookie Middleware: Encrypt and decrypt cookie values. (Coming soon)
- Timeout Middleware: Set a timeout for requests. (Coming soon)
Pulse is licensed under the MIT License. See LICENSE for the full license text.
Contributions are welcome! Please read the contribution guidelines first.
If you want to say thank you and/or support the active development of Pulse:
- Add a GitHub Star to the project.
- Tweet about the project on your Twitter
- Write a review or tutorial on Medium, dev.to, Reddit or personal blog.
- Buy Me a Coffee