Mortar is a GO framework/library for building gRPC (and REST) web services.

Overview

Mortar

Go codecov PkgGoDev Go Report Card

Mortar is a GO framework/library for building gRPC (and REST) web services. Mortar has out-of-the-box support for configuration, application metrics, logging, tracing, profiling, dependency injection and more. While it comes with predefined defaults Mortar gives you total control to fully customize it.

Demo

Clone this demo repository and play around.

When you done, read the documentation or create your own service with this template here.

Features

Telemetry (Everything connected)

  • Logs have Tracing Information traceId=6ff7e7e38d1e86f across services logs

  • Also visible in Jaeger traceId=6ff7e7e38d1e86f if it's sampled. jaeger

Support for *http.Client Interceptors, so you can

  • Add request and response info to Trace traceId=6ff7e7e38d1e86f

    jaeger_http

  • Log/Dump requests and/or responses when http request fails.

    return func(req *http.Request, handler client.HTTPHandler) (resp *http.Response, err error) {
        var reqBytes, respBytes []byte
        // If the response is Bad Request, log both Request and Response
        reqBytes, _ = httputil.DumpRequestOut(req, true) // it can be nil and it's ok
        if resp, err = handler(req); err == nil && resp.StatusCode >= http.StatusBadRequest {
            respBytes, _ = httputil.DumpResponse(resp, true) // it can be nil
            logger.WithError(fmt.Errorf("http request failed")).
            WithField("status",resp.StatusCode).
            Warn(req.Context(), "\nRequest:\n%s\n\nResponse:\n%s\n", reqBytes, respBytes)
        }
        return
    }

    http_client

  • Alter requests and/or responses (useful in Tests)

    func(*http.Request, clientInt.HTTPHandler) (*http.Response, error) {
        // special case, don't go anywhere just return the response
        return &http.Response{
            Status:        "200 OK",
            StatusCode:    200,
            Proto:         "HTTP/1.1",
            ProtoMajor:    1,
            ProtoMinor:    1,
            ContentLength: 11,
            Body:          ioutil.NopCloser(strings.NewReader("car painted")),
        }, nil
    }

Monitoring/Metrics support

Export to either Prometheus/Datadog/statsd/etc, it's your choice. Mortar only provides the Interface and also caches the metrics so you don't have to.

counter := w.deps.Metrics.WithTags(monitor.Tags{
 "color":   request.GetDesiredColor(),
 "success": fmt.Sprintf("%t", err == nil),
}).Counter("paint_desired_color", "New paint color for car")

counter.Inc()

counter is actually a singleton, uniqueness calculated here

grafana

For more information about Mortar Monitoring read here.

Additional Features

  • /debug/pprof and other useful handlers
  • Use config_test.yml during tests to override values in config.yml, it saves time.

There are some features not listed here, please check the Documentation for more.

Documentation

Mortar is not a drop-in replacement.

It's important to read its Documentation first.

Service Template

To help you bootstrap your services with Mortar here you can find a template.

You might also like...
Go based grpc - grpc gateway micro service example

go-grpc-gateway-server This repository provides an example for go based microservice. Go micro services developed based on gRPC protobuf's and also us

Go-grpc - This is grpc server for golang.

go-grpc This is grpc server for golang. protocのインストール brew install protoc Golang用のプラグインのインストール go install google.golang.org/protobuf/cmd/protoc-gen-go

GRPC - Creating a gRPC service from scratch

#Go gRPC services course Creating a gRPC service from scratch Command line colle

Grpc-gateway-map-null - gRPC Gateway test using nullable values in map

Demonstrate gRPC gateway behavior with nullable values in maps Using grpc-gatewa

Todo-app-grpc - Go/GRPC codebase containing RealWorld examples (CRUD, auth, advanced patterns, etc)

Go/GRPC codebase containing RealWorld examples (CRUD, auth, advanced patterns, e

GRPC - A client-server mockup, using gRPC to expose functionality.

gRPC This is a mockup application that I built to help me visualise and understand the basic concepts of gRPC. In this exchange, the client can use a

Raft-grpc-demo - Some example code for how to use Hashicorp's Raft implementation with gRPC

raft-grpc-example This is some example code for how to use Hashicorp's Raft impl

Benthos-input-grpc - gRPC custom benthos input

gRPC custom benthos input Create a custom benthos input that receives messages f

Go-grpc-template - A small template for quickly bootstrapping a, developer platform independent gRPC golang application
Go-grpc-template - A small template for quickly bootstrapping a, developer platform independent gRPC golang application

go-grpc-template A small template for quickly bootstrapping a developer platform

Comments
  • [feature] make newWebService injectable, server.webService public

    [feature] make newWebService injectable, server.webService public

    Does it ok to use oneport service more conveniently by replace newWebService and extend server.webService ?

    https://github.com/go-masonry/mortar/blob/master/constructors/service.go#L24

    https://github.com/go-masonry/mortar/blob/master/http/server/builders.go#L224

    thanks

    opened by xqbumu 3
  • [feature] Provide a way to custom runtime.ServerMux

    [feature] Provide a way to custom runtime.ServerMux

    Context: I need a way to add CORS support.

    Problem: Currently, there's no way to inject custom runtime.ServerMux and set it using RestBuilder.

    Solution: Add support to inject custom runtime.ServerMux at https://github.com/go-masonry/mortar/blob/f8601ac30dc0705ed82c0387864aaebbb6955abe/constructors/partial/httpserver.go#L50

    enhancement 
    opened by liemlhdbeatvn 3
Releases(v1.0.31)
Simple grpc web and grpc transcoding with Envoy

gRPC Web and gRPC Transcoding with Envoy This is a simple stand-alone set of con

null 0 Dec 25, 2021
Building microservice to list products of one ecommerce using golang and gRPC

Building microservice to list products of one ecommerce using golang and grpc Command for generate protobuf $ protoc -I ./protos/... file.proto --go_o

Isaque Veras 2 Mar 26, 2022
grpc-http1: A gRPC via HTTP/1 Enabling Library for Go

grpc-http1: A gRPC via HTTP/1 Enabling Library for Go This library enables using all the functionality of a gRPC server even if it is exposed behind a

StackRox 89 Dec 17, 2022
Totem - A Go library that can turn a single gRPC stream into bidirectional unary gRPC servers

Totem is a Go library that can turn a single gRPC stream into bidirectional unar

Joe Kralicky 3 Jan 6, 2023
⚡️Lightweight framework for microservices & web services in golang

Quickstart Zepto is a lightweight framework for the development of microservices & web services in golang. As an opinionated framework, zepto proposes

null 117 Jun 19, 2022
Server and client implementation of the grpc go libraries to perform unary, client streaming, server streaming and full duplex RPCs from gRPC go introduction

Description This is an implementation of a gRPC client and server that provides route guidance from gRPC Basics: Go tutorial. It demonstrates how to u

Joram Wambugu 0 Nov 24, 2021
Easily generate gRPC services in Go ⚡️

Lile is a application generator (think create-react-app, rails new or django startproject) for gRPC services in Go and a set of tools/libraries. The p

Lile 1.5k Dec 27, 2022
Using Envoy Proxy to load-balance gRPC services on GKE with header value based Session Affinity

Using Envoy Proxy to load-balance gRPC services on GKE with header value based S

Daniel William Clarke 2 Aug 24, 2022
Sagadt - gRPC based micro services POC

Sagadt gRPC based micro service POC development Tools gRPC gRPC gateway buf Prot

Andrei Silchankau 0 Jan 4, 2022
A suite of gRPC debugging tools. Like Fiddler/Charles but for gRPC.

grpc-tools A suite of tools for gRPC debugging and development. Like Fiddler/Charles but for gRPC! The main tool is grpc-dump which transparently inte

Bradley Kemp 1.1k Dec 22, 2022