zepto

package module
v1.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2021 License: MIT Imports: 16 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 HTTPServer added in v1.0.2

func HTTPServer(s *http.Server) Option

HTTPServer - Use a custom HTTP Server

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 SessionName added in v1.0.2

func SessionName(name string) Option

SessionName - Set the session name

func SessionStore added in v1.0.2

func SessionStore(store sessions.Store) Option

SessionStore - Set the session name

func TemplateEngine added in v1.0.2

func TemplateEngine(tmplEngine renderer.Engine) Option

TemplateEngine - Change the template engine implementation

func Version

func Version(v string) Option

Name of Zepto App

func WebpackEnabled added in v1.0.2

func WebpackEnabled(enabled bool) Option

type Options

type Options struct {
	Name           string
	Version        string
	Env            string
	Logger         logger.Logger
	WebpackEnabled bool
	TmplEngine     renderer.Engine
	SessionName    string
	SessionStore   sessions.Store
	// Custom HTTP server
	HTTPServer *http.Server
}

type Plugin added in v1.0.2

type Plugin interface {
	Name() string
	Instance() interface{}
	PrependMiddlewares() []web.MiddlewareFunc
	AppendMiddlewares() []web.MiddlewareFunc
	OnCreated(z *Zepto)
	OnZeptoInit(z *Zepto)
	OnZeptoStart(z *Zepto)
	OnZeptoStop(z *Zepto)
}

type Zepto

type Zepto struct {
	*web.App
	// contains filtered or unexported fields
}

func NewZepto

func NewZepto(opts ...Option) *Zepto

func (*Zepto) AddPlugin added in v1.0.2

func (z *Zepto) AddPlugin(plugin Plugin)

func (*Zepto) InitApp added in v1.0.2

func (z *Zepto) InitApp()

func (*Zepto) InitMailer

func (z *Zepto) InitMailer()

func (*Zepto) Logger

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

func (*Zepto) Plugins added in v1.0.2

func (z *Zepto) Plugins() map[string]Plugin

func (*Zepto) SetupGRPC

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

func (*Zepto) SetupHTTP

func (z *Zepto) SetupHTTP(addr string)

func (*Zepto) Start

func (z *Zepto) Start()

Jump to

Keyboard shortcuts

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