Skip to content

gebes/there

Repository files navigation

Gopher There

Effortless Go Routing: Build Powerful Services with Minimal Overhead

Made with Go Go Version Documentation GoDoc GoReportCard License Latest release

🔥 Get Started

🔨 Create a Project

  1. Ensure you have Go installed.
  2. Create a project with go mod init github.com/{user}/{repository}
  3. Install there with the go get command
go get -u github.com/gebes/there/v2
  1. 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

🚀 Introducing there - Simplify Your Go Routing

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.

Why Choose there?

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.

⭐️ Key Features

Minimalistic Control Flow

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)
}

🧑‍💻 View full code example

Straightforward Routing

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

Expandable - Customize Your Control Flow

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))
}

🧑‍💻 View full code example

🌟 Additional Features for the Skeptical Gophers

Complete Middleware Support

Utilize existing middleware with minimal changes or create specific middleware for individual routes, enhancing flexibility and control over the request/response lifecycle.

Lightweight - No Dependencies

there is designed to be dependency-free, ensuring a lightweight integration into your projects without bloating your application.

Robust and Tested

With nearly complete test coverage, there is proven in production environments, offering reliability and stability for your critical applications.

Easy Integration with Existing Code

Thanks to there's compatibility and flexible architecture, integrating with existing Go codebases and middleware is seamless and straightforward.

Performance

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:

👨‍💻 Contributions

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.

Maintained? Maintainer