Skip to content

Gotham is a simple&pure protobuffers tcp server written in go(Golang). It features a Gin-like API for easy access.

License

Notifications You must be signed in to change notification settings

sleep2death/gotham

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gotham

Build Status Go Report Card codecov

A well-tested/high-performace tcp/protobuf router written in go, highly inspired by Gin, and the source of standard http library:net/http/server.go.

content

Installation

To install gotham package, you need to install Go and set your Go workspace first.

  1. The first need Go installed (version 1.11+ is required), then you can use the below Go command to install Gotham.
$ go get -u github.com/sleep2death/gotham
  1. Import it in your code:
import "github.com/sleep2death/gotham"

Quick start

All examples you can find are in /examples folder.

package main

import (
	"log"
	"net/http"

	"github.com/golang/protobuf/proto"
	"github.com/golang/protobuf/ptypes"

	"github.com/sleep2death/gotham"
	"github.com/sleep2death/gotham/examples/pb"
)

func main() {
	// SERVER
	// Starts a new gotham instance without any middleware attached.
	router := gotham.New()

	// Define your handlers.
	router.Handle("/pb/EchoMessage", func(c *gotham.Context) {
		message := new(pb.EchoMessage)

		// If some error fires, you can abort the request.
		if err := proto.Unmarshal(c.Data(), message); err != nil {
			c.AbortWithStatus(http.StatusBadRequest)
			return
		}

		// log.Printf("Ping request received at %s", ptypes.TimestampString(message.Ts))
		message.Message = "Pong"
		message.Ts = ptypes.TimestampNow()
		c.Write(message)
	})

	// Run, gotham, Run...
	addr := ":9090"
	log.Fatal(router.Run(addr))
}

About

Gotham is a simple&pure protobuffers tcp server written in go(Golang). It features a Gin-like API for easy access.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages