zepto

package module
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2020 License: MIT Imports: 14 Imported by: 3

README

Quickstart

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. But not only that. It is a framework prepared for the development of complete web applications.

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
  • Web Module:
    • Routing
    • Middlewares
    • Template Rendering
    • Debug Mode
    • Cookie
    • Session
    • File Upload
    • Static Files
    • Sass & JS building with webpack (dev and prod)
    • Error Handler
    • Testing Utilities

A Minimal Application

A minimal Zepto application looks something like this:

package main

import (
	"github.com/go-zepto/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()
}

Instalation

With zepto you can easily create a project with the CLI tool:

go get -u github.com/go-zepto/zepto-cli/cmd/zepto

Create a Project

If you want to create a project, just run this command:

zepto new <PROJECT_TYPE> github.com/username/project

Available project types:

  • ms: It only includes the Zepto core like HTTP, gRPC, Healthcheck, Broker and all the basic structure to start the development and deployment of a microservice

  • web: It includes the zepto core and also the web module that includes routing, templating, cookie, session, file upload, static files, assets building (webpack).

Examples:

# ms
zepto new ms github.com/username/my-microservice

# web
zepto new web github.com/username/my-web

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

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