https://github.com/sleep2death/gotham
Gotham is a simple&pure protobuffers tcp server written in go(Golang). It features a Gin-like API for easy access.
https://github.com/sleep2death/gotham
go protobuf server socket tcp
Last synced: 20 days ago
JSON representation
Gotham is a simple&pure protobuffers tcp server written in go(Golang). It features a Gin-like API for easy access.
- Host: GitHub
- URL: https://github.com/sleep2death/gotham
- Owner: sleep2death
- License: mit
- Created: 2018-12-09T12:30:43.000Z (about 7 years ago)
- Default Branch: main
- Last Pushed: 2022-06-12T02:06:59.000Z (over 3 years ago)
- Last Synced: 2024-06-21T18:48:41.004Z (over 1 year ago)
- Topics: go, protobuf, server, socket, tcp
- Language: Go
- Homepage:
- Size: 189 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gotham
[](https://travis-ci.com/sleep2death/gotham)
[](https://goreportcard.com/report/github.com/sleep2death/gotham)
[](https://codecov.io/gh/sleep2death/gotham)
A well-tested/high-performace tcp/protobuf router written in go, highly inspired by [Gin](https://github.com/gin-gonic/gin), and the source of standard http library:[net/http/server.go](https://github.com/golang/go/blob/master/src/net/http/server.go).
## content
- [Installation](#installation)
- [Quick start](#quick-start)
## Installation
To install gotham package, you need to install Go and set your Go workspace first.
1. The first need [Go](https://golang.org/) installed (**version 1.11+ is required**), then you can use the below Go command to install Gotham.
```sh
$ go get -u github.com/sleep2death/gotham
```
2. Import it in your code:
```go
import "github.com/sleep2death/gotham"
```
## Quick start
All examples you can find are in `/examples` folder.
```go
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))
}
```