pluto

package module
v6.7.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: MIT Imports: 24 Imported by: 0

README

Pluto

An implementation of microservices with golang to tackle some of the challenges in distributed systems.

Features
  • Currently supports a multiplexer HTTP router with dynamic paths and still compatible with the standard net/http library.
  • Client/Server implementation with gRPC for communication between services.
  • Service health check.
  • Structured Logs by using zerolog.
Inspiration

Projects that had influence in Pluto design and helped to solve technical barriers.

Books

Articles

Examples
Pluto - Hello World
package main

import (
	"log"
	"net/http"

	"github.com/aukbit/pluto/v6"
	"github.com/aukbit/pluto/v6/reply"
	"github.com/aukbit/pluto/v6/server"
	"github.com/aukbit/pluto/v6/server/router"
)

func main() {
	// Define router
	mux := router.New()
	mux.GET("/", func(w http.ResponseWriter, r *http.Request) {
		reply.Json(w, r, http.StatusOK, "Hello World")
	})

	// Define http server
	srv := server.New(
		server.Mux(mux),
	)

	// Define Pluto service
	s := pluto.New(
		pluto.Servers(srv),
	)

	// Run Pluto service
	if err := s.Run(); err != nil {
		log.Fatal(err)
	}
}

go run ./examples/hello/main.go
{"timestamp":"2017-08-15T11:40:44.117833902+01:00","severity":"info","id":"plt_CDVNVF","name":"pluto","ip4":"192.168.15.60","servers":2,"clients":0,"message":"starting pluto, servers: 2 clients: 0"}
{"timestamp":"2017-08-15T11:40:44.118181195+01:00","severity":"info","id":"plt_CDVNVF","name":"pluto","server":{"id":"srv_I3JQ3L","name":"server","format":"http","port":":8080"},"message":"starting http server, listening on :8080"}
{"timestamp":"2017-08-15T11:40:44.118130789+01:00","severity":"info","id":"plt_CDVNVF","name":"pluto","server":{"id":"srv_FP9BC7","name":"pluto_health_server","format":"http","port":":9090"},"message":"starting http pluto_health_server, listening on :9090"}
{"timestamp":"2017-08-15T11:40:55.106279683+01:00","severity":"info","id":"plt_CDVNVF","name":"pluto","server":{"id":"srv_I3JQ3L","name":"server","format":"http","port":":8080"},"eid":"N5G58UTAHSTHEPZQ","method":"GET","url":"/","proto":"HTTP/1.1","remote_addr":"[::1]:50853","header":{"Connection":["keep-alive"],"Upgrade-Insecure-Requests":["1"],"User-Agent":["Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36"],"Accept":["text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8"],"Accept-Encoding":["gzip, deflate, br"],"Accept-Language":["en-US,en;q=0.8,pt;q=0.6"]},"message":"GET / HTTP/1.1"}
{"timestamp":"2017-08-15T11:41:02.795156001+01:00","severity":"info","id":"plt_CDVNVF","name":"pluto","message":"shutting down, got signal: interrupt"}
{"timestamp":"2017-08-15T11:41:02.79527628+01:00","severity":"warn","id":"plt_CDVNVF","name":"pluto","server":{"id":"srv_FP9BC7","name":"pluto_health_server","format":"http","port":":9090"},"message":"pluto_health_server has just exited"}
{"timestamp":"2017-08-15T11:41:02.795296844+01:00","severity":"warn","id":"plt_CDVNVF","name":"pluto","server":{"id":"srv_I3JQ3L","name":"server","format":"http","port":":8080"},"message":"server has just exited"}
{"timestamp":"2017-08-15T11:41:02.79531183+01:00","severity":"warn","id":"plt_CDVNVF","name":"pluto","message":"pluto has just exited"}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDatastoreNotInitialized = errors.New("datastore not initialized")
)
View Source
var (
	// PlutoContextKey is a context key. It can be used in HTTP / GRPC
	// handlers with context.WithValue to access the server that
	// started the handler. The associated value will be of type *Server.
	PlutoContextKey = &contextKey{"pluto-server"}
)

Functions

func Call added in v6.1.0

func Call(ctx context.Context, clientName, methodName string, args ...interface{}) (interface{}, error)

Call invoque's the methodName in the specific clientName initialize

func CallWithCredentials added in v6.2.0

func CallWithCredentials(ctx context.Context, clientName, methodName string, args ...interface{}) (interface{}, error)

CallWithCredentials invoque's the methodName in the specific clientName initialize

func FromContextAny

func FromContextAny(ctx context.Context, key string) interface{}

FromContextAny returns from context the interface value to which the key is associated.

func WithContextAny

func WithContextAny(ctx context.Context, key string, val interface{}) context.Context

WithContextAny returns a copy of parent ctx in which the value associated with key is val.

Types

type Config

type Config struct {
	ID          string
	Name        string
	Description string

	Discovery  discovery.Discovery
	HealthAddr string // TCP address (e.g. localhost:8000) to listen on, ":http" if empty
	Servers    map[string]*server.Server
	Clients    map[string]*client.Client
	Hooks      map[string][]HookFunc
	// contains filtered or unexported fields
}

Config pluto service config

type HookFunc

type HookFunc func(context.Context) error

HookFunc hook function type

type Option

type Option interface {
	// contains filtered or unexported methods
}

Option is used to set options for the service.

func Clients

func Clients(clt *client.Client) Option

Clients slice of service clients

func Description

func Description(d string) Option

Description service description

func Discovery

func Discovery(d discovery.Discovery) Option

Discovery service discoery

func HealthAddr

func HealthAddr(a string) Option

HealthAddr health server address

func HookAfterStart

func HookAfterStart(fn ...HookFunc) Option

HookAfterStart execute functions after service starts

func ID

func ID(id string) Option

ID service id

func Logger

func Logger(l zerolog.Logger) Option

Logger sets a new configuration for service logger

func Name

func Name(n string) Option

Name service name

func Servers

func Servers(srv *server.Server) Option

Servers slice of service servers

type Service

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

Service representacion of a pluto service

func FromContext

func FromContext(ctx context.Context) *Service

FromContext returns pluto service pointer from a context

func New

func New(opts ...Option) *Service

New returns a new pluto service with Options passed in

func (*Service) Client

func (s *Service) Client(name string) (clt *client.Client, ok bool)

Client returns a client instance by name if initialized in service

func (*Service) Health

func (s *Service) Health() *healthpb.HealthCheckResponse

Health ...

func (*Service) ID

func (s *Service) ID() string

ID returns service id

func (*Service) Logger

func (s *Service) Logger() zerolog.Logger

Logger returns service logger

func (*Service) Name

func (s *Service) Name() string

Name returns service name

func (*Service) Push

func (s *Service) Push(opts ...Option)

Push allows to start additional options while service is running

func (*Service) Run

func (s *Service) Run() error

Run starts service

func (*Service) Server

func (s *Service) Server(name string) (srv *server.Server, ok bool)

Server returns a server instance by name if initialized in service

func (*Service) Stop

func (s *Service) Stop()

Stop stops service

func (*Service) WaitUntilFinish

func (s *Service) WaitUntilFinish()

WaitUntilFinish returns service name

func (*Service) WithContext

func (s *Service) WithContext(ctx context.Context) context.Context

WithContext returns a copy of parent ctx with pluto service associated.

func (*Service) WithOptions

func (s *Service) WithOptions(opts ...Option) *Service

WithOptions clones the current Service, applies the supplied Options, and returns the resulting Service. It's safe to use concurrently.

Directories

Path Synopsis
jws
Package jws copied from https://github.com/golang/oauth2/blob/master/jws/jws.go
Package jws copied from https://github.com/golang/oauth2/blob/master/jws/jws.go
jwt
Package common contains helper functions to be used around
Package common contains helper functions to be used around
examples
ext
router
Package router trie based on a 256-way trie expressed on the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne A string symbol table for extended ASCII strings, implemented using a 256-way trie.
Package router trie based on a 256-way trie expressed on the textbook Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne A string symbol table for extended ASCII strings, implemented using a 256-way trie.
test

Jump to

Keyboard shortcuts

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