|
1 |
| -# Pulse Web framework (In Development) |
| 1 | +# Pulse Web framework for Go |
2 | 2 |
|
3 |
| -Pulse is a web framework for the Go programming language. It is a lightweight framework that is easy to use and easy to learn. It is designed to be a simple and elegant solution to building web applications and APIs. |
| 3 | +[](https://goreportcard.com/report/github.com/gopulse/pulse) |
| 4 | +[](LICENSE) |
| 5 | +[](https://pkg.go.dev/github.com/gopulse/pulse) |
| 6 | +[](https://pkg.go.dev/github.com/gopulse/pulse#pkg-overview) |
| 7 | + |
| 8 | + |
| 9 | +**Pulse** is a web framework for the Go programming language. It is a lightweight framework that is easy to use and easy to learn. |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- Routing |
| 14 | +- Static files |
| 15 | +- Simple and elegant API |
| 16 | +- Middleware support |
| 17 | +- Validation |
| 18 | +- Routes grouping |
| 19 | + |
| 20 | +### Installation |
| 21 | + |
| 22 | +Make sure you have Go installed on your machine. Then run the following command: |
| 23 | + |
| 24 | +Initialize your project ([Learn](https://go.dev/blog/using-go-modules)). Then install **Pulse** with the go get command: |
| 25 | + |
| 26 | +```bash |
| 27 | +go get github.com/gopulse/pulse |
| 28 | +``` |
| 29 | + |
| 30 | +### Getting Started |
| 31 | + |
| 32 | +```go |
| 33 | +package main |
| 34 | + |
| 35 | +import ( |
| 36 | + "github.com/gopulse/pulse" |
| 37 | +) |
| 38 | + |
| 39 | +func main() { |
| 40 | + app := pulse.New() |
| 41 | + router := pulse.NewRouter() |
| 42 | + |
| 43 | + app.Router = router |
| 44 | + |
| 45 | + router.Get("/", func(c *pulse.Context) error { |
| 46 | + c.String("Hello, World!") |
| 47 | + return nil |
| 48 | + }) |
| 49 | + |
| 50 | + app.Run(":3000") |
| 51 | +} |
| 52 | +``` |
| 53 | + |
| 54 | +### Examples |
| 55 | + |
| 56 | +- Routing |
| 57 | + |
| 58 | +Supports `GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD, CONNECT, TRACE` |
| 59 | + |
| 60 | +```go |
| 61 | +package main |
| 62 | + |
| 63 | +import ( |
| 64 | + "github.com/gopulse/pulse" |
| 65 | +) |
| 66 | + |
| 67 | +func main() { |
| 68 | + app := pulse.New() |
| 69 | + router := pulse.NewRouter() |
| 70 | + |
| 71 | + // GET /hello |
| 72 | + router.Get("/", func(c *pulse.Context) error { |
| 73 | + c.String("Hello, World!") |
| 74 | + return nil |
| 75 | + }) |
| 76 | + |
| 77 | + // GET /hello/:name |
| 78 | + router.Get("/profile/:id", func(c *pulse.Context) error { |
| 79 | + c.String("Profile: " + c.Param("id")) |
| 80 | + return nil |
| 81 | + }) |
| 82 | + |
| 83 | + // GET /user/ |
| 84 | + router.Get("/user/*", func(c *pulse.Context) error { |
| 85 | + c.String("Hello, World!") |
| 86 | + return nil |
| 87 | + }) |
| 88 | + |
| 89 | + app.Router = router |
| 90 | + |
| 91 | + app.Run(":3000") |
| 92 | +} |
| 93 | +``` |
| 94 | + |
| 95 | +* Static files |
| 96 | + |
| 97 | +```go |
| 98 | +package main |
| 99 | + |
| 100 | +import ( |
| 101 | + "github.com/gopulse/pulse" |
| 102 | + "time" |
| 103 | +) |
| 104 | + |
| 105 | +func main() { |
| 106 | + app := pulse.New() |
| 107 | + router := pulse.NewRouter() |
| 108 | + |
| 109 | + // Static files (./static) with cache duration 24 hours |
| 110 | + router.Static("/", "./static", &pulse.Static{ |
| 111 | + Compress: true, |
| 112 | + ByteRange: false, |
| 113 | + IndexName: "index.html", |
| 114 | + CacheDuration: 24 * time.Hour, |
| 115 | + }) |
| 116 | + |
| 117 | + app.Router = router |
| 118 | + |
| 119 | + app.Run(":3000") |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +* Middleware |
| 124 | + |
| 125 | +```go |
| 126 | +package main |
| 127 | + |
| 128 | +import ( |
| 129 | + "github.com/gopulse/pulse" |
| 130 | +) |
| 131 | + |
| 132 | +func main() { |
| 133 | + app := pulse.New() |
| 134 | + router := pulse.NewRouter() |
| 135 | + |
| 136 | + router.Get("/profile/:name", func(ctx *pulse.Context) error { |
| 137 | + if ctx.Param("name") != "test" { |
| 138 | + ctx.Abort() |
| 139 | + ctx.Status(404) |
| 140 | + return nil |
| 141 | + } |
| 142 | + ctx.String("hello") |
| 143 | + ctx.Next() |
| 144 | + return nil |
| 145 | + }) |
| 146 | + |
| 147 | + app.Router = router |
| 148 | + |
| 149 | + app.Run(":3000") |
| 150 | +} |
| 151 | +``` |
| 152 | + |
| 153 | +## Available Middleware |
| 154 | + |
| 155 | +- [x] CORS Middleware: Enable cross-origin resource sharing (CORS) with various options. |
| 156 | +```go |
| 157 | +package main |
| 158 | + |
| 159 | +import ( |
| 160 | + "github.com/gopulse/pulse" |
| 161 | +) |
| 162 | + |
| 163 | +func main() { |
| 164 | + app := pulse.New() |
| 165 | + router := pulse.NewRouter() |
| 166 | + |
| 167 | + router.Get("/", func(ctx *pulse.Context) error { |
| 168 | + return nil |
| 169 | + }) |
| 170 | + |
| 171 | + router.Use("GET", pulse.CORSMiddleware()) |
| 172 | + |
| 173 | + app.Router = router |
| 174 | + |
| 175 | + app.Run(":3000") |
| 176 | +} |
| 177 | +``` |
| 178 | + |
| 179 | +- [ ] Logger Middleware: Log every request with configurable options. **(Coming soon)** |
| 180 | +- [ ] Encrypt Cookie Middleware: Encrypt and decrypt cookie values. **(Coming soon)** |
| 181 | +- [ ] Timeout Middleware: Set a timeout for requests. **(Coming soon)** |
| 182 | + |
| 183 | +## License |
| 184 | + |
| 185 | +Pulse is licensed under the MIT License. See [LICENSE](LICENSE) for the full license text. |
| 186 | + |
| 187 | +## Contributing |
| 188 | + |
| 189 | +Contributions are welcome! Please read the [contribution guidelines](CONTRIBUTING.md) first. |
| 190 | + |
| 191 | +## Support |
| 192 | + |
| 193 | +If you want to say thank you and/or support the active development of Pulse: |
| 194 | +1. Add a [GitHub Star](star) to the project. |
| 195 | +2. Tweet about the project [on your Twitter](https://twitter.com/intent/tweet?text=Pulse%20is%20a%20%23web%20%23framework%20for%20the%20%23Go%20programming%20language.%20It%20is%20a%20lightweight%20framework%20that%20is%20%23easy%20to%20use%20and%20easy%20to%20learn.%20It%20is%20designed%20to%20be%20a%20simple%20and%20elegant%20solution%20for%20building%20web%20applications%20and%20%23APIs%20%F0%9F%9A%80%20https%3A%2F%2Fgithub.com%2Fgopulse%2Fpulse) |
| 196 | +3. Write a review or tutorial on [Medium](https://medium.com/), [dev.to](https://dev.to/), [Reddit](https://www.reddit.com/) or personal blog. |
| 197 | +4. [Buy Me a Coffee](https://www.buymeacoffee.com/gopulse) |
| 198 | + |
| 199 | +## Contributors |
| 200 | +<!-- CONTRIBUTORS-START --> |
| 201 | +<a href="https://github.com/gopulse/pulse/graphs/contributors"> |
| 202 | + <img src="https://contrib.rocks/image?repo=gopulse/pulse&columns=18" /> |
| 203 | +</a> |
| 204 | +<!-- CONTRIBUTORS-END --> |
| 205 | + |
| 206 | +# Stargarazers over time |
| 207 | + |
| 208 | +[](https://starchart.cc/gopulse/pulse) |
0 commit comments