zepto

package module
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2020 License: MIT Imports: 14 Imported by: 3

README

zepto ⚡️

Zepto is a lightweight framework for the development of microservices & web services in golang.

As an opinionated framework, zepto proposes to have a quick setup and with the greatest needs for the development of modern microservices.

See below some of our features:

  • gRPC & HTTP support
  • Broker: Publish & Subscribe Events
    • Google Pub/Sub
    • Kafka (Comming soon...)
    • RabbitMQ (Comming soon)
  • Healthcheck
  • Gracefully Shutdown
  • Pretty & Plugabble Logger

Quick Start

package main

import (
	"github.com/carlosstrand/zepto"
	"github.com/gorilla/mux"
	"net/http"
)

func main() {
	z := zepto.NewZepto(
		zepto.Name("ms.hello.world"),
		zepto.Version("latest"),
	)

	r := mux.NewRouter()

	r.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
		_, _ = w.Write([]byte("Hello, World!"))
	})

	// Setup HTTP Server
	z.SetupHTTP("0.0.0.0:8000", r)

	z.Start()
}

HTTP & gRPC

With zepto, you can easily set up an HTTP and/or gRPC server. Both can work simultaneously.

	// Setup gRPC Server
	z.SetupGRPC("0.0.0.0:9000", func(s *grpc.Server) {
		pb.RegisterTodosServer(s, handlers.NewGRPCHandler(svc))
	})

	// Setup HTTP Server
	z.SetupHTTP("0.0.0.0:8000", handlers.NewHTTPHandler(svc))

Broker/PubSub

Publish and Receive messages in an easy way. Zepto abstracts all the encode/decode logic behind sending and receiving messages from your broker.It is also extensible, as it has an interface layer that facilitates the creation of new brokers.

Broker Setup

	// Setup Broker Provider (Google Pub/Sub)
	z.SetupBroker(gcp.NewBroker(
		gcp.ProjectID("my-project"),
		gcp.TopicPrefix("dev.accounts."),
	))

Subscribe to Messages

	z.Broker().Subscribe("created", func(ctx context.Context, user *pb.User) {
        fmt.Println("User created account: " + user.Name)
    })

Publish Messages

    z.Broker().Publish(ctx, "created", user)

Logging

Zepto uses the Logrus library for Logging. It is extensible and customizable. You can define the log format you want, as well as which channel you want to log to. By default, our log looks like the one in the image below:

logger

What's next

The next steps will be to support other brokers like kafka and rabbitmq. It is also in my planning to create a zepto-cli to easily create projects using zepto.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewLoggingResponseWriter

func NewLoggingResponseWriter(w http.ResponseWriter) *loggingResponseWriter

Types

type HTTPZeptoHandler

type HTTPZeptoHandler struct {
	// contains filtered or unexported fields
}

func (*HTTPZeptoHandler) ServeHTTP

func (h *HTTPZeptoHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HealthHandler

type HealthHandler struct {
	// contains filtered or unexported fields
}

type HealthStatus

type HealthStatus struct {
	Name    string `json:"name"`
	Version string `json:"version"`
	Age     string `json:"age"`
}

type Option

type Option func(*Options)

func Logger

func Logger(l logger.Logger) Option

Logger is the mains logger used in all zepto app

func Name

func Name(n string) Option

Zepto App Name

func Version

func Version(v string) Option

Name of Zepto App

type Options

type Options struct {
	Name    string
	Version string
	Env     string
	Logger  logger.Logger
}

type Zepto

type Zepto struct {
	// contains filtered or unexported fields
}

func NewZepto

func NewZepto(opts ...Option) *Zepto

func (*Zepto) Broker

func (z *Zepto) Broker() *broker.Broker

func (*Zepto) Logger

func (z *Zepto) Logger() logger.Logger

func (*Zepto) NewWeb

func (z *Zepto) NewWeb() *web.App

func (*Zepto) SetupBroker

func (z *Zepto) SetupBroker(bp broker.BrokerProvider)

func (*Zepto) SetupGRPC

func (z *Zepto) SetupGRPC(addr string, fn func(s *grpc.Server))

func (*Zepto) SetupHTTP

func (z *Zepto) SetupHTTP(addr string, handler http.Handler)

func (*Zepto) Start

func (z *Zepto) Start()

Directories

Path Synopsis
gcp
web

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL