- Notifications
You must be signed in to change notification settings - Fork5
⚡️ Robust Web Framework to build Go Services
License
gebes/there
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Effortless Go Routing: Build Powerful Services with Minimal Overhead
- Ensure you haveGo 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 mainimport ("github.com/gebes/there/v2""github.com/gebes/there/v2/status""log")funcmain() {router:=there.NewRouter()router.Get("/",func(request there.Request) there.Response {returnthere.Json(status.OK,map[string]string{"message":"Hello World!",})})err:=router.Listen(8080)iferr!=nil {log.Fatalln(err)}}
📚 Check the Documentation for more info
Welcome tothere
, a Go routing library designed to streamline your project's API development. By wrapping the defaulthttp 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. Withthere
, you can manage response handlingintuitively 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:
funcCreatePost(request there.Request) there.Response {varbodyPosterr:=request.Body.BindJson(&body)iferr!=nil {returnthere.Error(status.BadRequest,"could not parse body: "+err.Error()) }ifpostById(body.Id)!=nil {returnthere.Error(status.Conflict,"post with this ID already exists") }posts=append(posts,body)returnthere.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 extendthere
by adding your own responses like a Msgpack response, without the need for third-partydependencies:
import ("github.com/gebes/there/v2""github.com/vmihailenco/msgpack/v5")funcMsgpack(codeint,datainterface{}) there.Response {msgpackData,err:=msgpack.Marshal(data)iferr!=nil {panic(err) }returnthere.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, enhancingflexibility and control over the request/response lifecycle.
there
is designed to be dependency-free, ensuring a lightweight integration into your projects without bloating yourapplication.
With nearly complete test coverage,there
is proven in production environments, offering reliability and stability foryour critical applications.
Thanks tothere
's compatibility and flexible architecture, integrating with existing Go codebases and middleware isseamless 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. Everyhelpful hand is welcomed.
About
⚡️ Robust Web Framework to build Go Services