Effortless Go Routing: Build Powerful Services with Minimal Overhead
- Ensure you have Go installed.
- Create a project with
go mod init github.com/{user}/{repository}
- Install
there
with thego get
command
go get -u github.com/gebes/there/v2
- Create a
main.go
file
package main
import (
"github.com/gebes/there/v2"
"github.com/gebes/there/v2/status"
"log"
)
func main() {
router := there.NewRouter()
router.Get("/", func(request there.Request) there.Response {
return there.Json(status.OK, map[string]string{
"message": "Hello World!",
})
})
err := router.Listen(8080)
if err != nil {
log.Fatalln(err)
}
}
📚 Check the Documentation for more info
Welcome to there
, a Go routing library designed to streamline your project's API development. By wrapping the default
http mux, there
enhances control flow without stripping away the flexibility and power of standard HTTP capabilities.
Developing robust APIs doesn't have to be complicated or time-consuming. With there
, you can manage response handling
intuitively and efficiently, avoiding the common pitfalls and verbosity typical of many routing frameworks.
- Error Handling Simplified: Encounter an error? Respond with
return Error(status, err)
. - Effortless Data Response: Need to send data? Use
return Json(status, data)
. - Optimize Large Data Transfers: Have large data? Compress easily with
return Gzip(Json(status, data))
.
This approach ensures your code is cleaner, more readable, and maintains full HTTP functionality.
Enjoy simple and clear control flow in your routes with out-of-the-box handlers that make coding a breeze:
func CreatePost(request there.Request) there.Response {
var body Post
err := request.Body.BindJson(&body)
if err != nil {
return there.Error(status.BadRequest, "could not parse body: " + err.Error())
}
if postById(body.Id) != nil {
return there.Error(status.Conflict, "post with this ID already exists")
}
posts = append(posts, body)
return there.Json(status.Created, body)
}
there
makes routing straightforward. Define routes and methods easily with groupings and middleware support:
router := there.NewRouter()
router.Group("/user")
.Get("/", Handler)
.Post("/", Handler)
.Patch("/", Handler)
router.Group("/user/post")
.Get("/{id}", Handler)
.Post("/", Handler)
router.Get("/details", Handler)
🧑💻 View full code example and best practices
Easily extend there
by adding your own responses like a Msgpack response, without the need for third-party
dependencies:
import (
"github.com/gebes/there/v2"
"github.com/vmihailenco/msgpack/v5"
)
func Msgpack(code int, data interface{}) there.Response {
msgpackData, err := msgpack.Marshal(data)
if err != nil {
panic(err)
}
return there.WithHeaders(map[string]string{
there.ResponseHeaderContentType: "application/x-msgpack",
}, there.Bytes(code, msgpackData))
}
Utilize existing middleware with minimal changes or create specific middleware for individual routes, enhancing flexibility and control over the request/response lifecycle.
there
is designed to be dependency-free, ensuring a lightweight integration into your projects without bloating your
application.
With nearly complete test coverage, there
is proven in production environments, offering reliability and stability for
your critical applications.
Thanks to there
's compatibility and flexible architecture, integrating with existing Go codebases and middleware is
seamless and straightforward.
there
is as efficient as it gets—built on the default http mux, it matches routes without any performance overhead.
Just focus on building your application; there
handles the rest.
Check out our benchmarks for more details:
Feel free to contribute to this project in any way! May it be a simple issue, idea or a finished pull request. Every helpful hand is welcomed.