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 ¶
- Variables
- func Call(ctx context.Context, clientName, methodName string, args ...interface{}) (interface{}, error)
- func CallWithCredentials(ctx context.Context, clientName, methodName string, args ...interface{}) (interface{}, error)
- func FromContextAny(ctx context.Context, key string) interface{}
- func WithContextAny(ctx context.Context, key string, val interface{}) context.Context
- type Config
- type HookFunc
- type Option
- func Clients(clt *client.Client) Option
- func Description(d string) Option
- func Discovery(d discovery.Discovery) Option
- func HealthAddr(a string) Option
- func HookAfterStart(fn ...HookFunc) Option
- func ID(id string) Option
- func Logger(l zerolog.Logger) Option
- func Name(n string) Option
- func Servers(srv *server.Server) Option
- type Service
- func (s *Service) Client(name string) (clt *client.Client, ok bool)
- func (s *Service) Health() *healthpb.HealthCheckResponse
- func (s *Service) ID() string
- func (s *Service) Logger() zerolog.Logger
- func (s *Service) Name() string
- func (s *Service) Push(opts ...Option)
- func (s *Service) Run() error
- func (s *Service) Server(name string) (srv *server.Server, ok bool)
- func (s *Service) Stop()
- func (s *Service) WaitUntilFinish()
- func (s *Service) WithContext(ctx context.Context) context.Context
- func (s *Service) WithOptions(opts ...Option) *Service
Constants ¶
This section is empty.
Variables ¶
var (
ErrDatastoreNotInitialized = errors.New("datastore not initialized")
)
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 ¶
FromContextAny returns from context the interface value to which the key is associated.
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 Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is used to set options for the service.
func HookAfterStart ¶
HookAfterStart execute functions after service starts
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service representacion of a pluto service
func FromContext ¶
FromContext returns pluto service pointer from a context
func (*Service) WaitUntilFinish ¶
func (s *Service) WaitUntilFinish()
WaitUntilFinish returns service name
func (*Service) WithContext ¶
WithContext returns a copy of parent ctx with pluto service associated.
func (*Service) WithOptions ¶
WithOptions clones the current Service, applies the supplied Options, and returns the resulting Service. It's safe to use concurrently.
Source Files
¶
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 |
Package common contains helper functions to be used around
|
Package common contains helper functions to be used around |
examples
|
|
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
|
|