Compare commits
11 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
1ce0df4e63 | ||
|
415fb3a730 | ||
|
172ffee8c3 | ||
|
48c068d88d | ||
|
3f7152a4f5 | ||
|
54f58a15d3 | ||
|
bcb6c12aa1 | ||
|
1cb40831a4 | ||
|
d9fc2c922d | ||
|
212c6c5ae9 | ||
|
1d8047a272 |
11
README.md
11
README.md
@@ -1,9 +1,8 @@
|
||||
# Go Micro [](https://opensource.org/licenses/Apache-2.0) [](https://godoc.org/github.com/micro/go-micro) [](https://travis-ci.org/micro/go-micro) [](https://goreportcard.com/report/github.com/micro/go-micro)
|
||||
|
||||
Go Micro is a pluggable RPC framework for distributed systems development.
|
||||
|
||||
The **micro** philosophy is sane defaults with a pluggable architecture. We provide defaults to get you started quickly but everything can be easily swapped out. It comes with built in support for {json,proto}-rpc encoding, consul or multicast dns for service discovery, http for communication and random hashed client side load balancing.
|
||||
Go Micro is a pluggable framework for microservice development.
|
||||
|
||||
The **micro** philosophy is sane defaults with a pluggable architecture. We provide defaults to get you started quickly but everything can be swapped out.
|
||||
Plugins are available at [github.com/micro/go-plugins](https://github.com/micro/go-plugins).
|
||||
|
||||
Follow us on [Twitter](https://twitter.com/microhq) or join the [Slack](http://slack.micro.mu/) community.
|
||||
@@ -15,12 +14,12 @@ Go Micro abstracts away the details of distributed systems. Here are the main fe
|
||||
- **Service Discovery** - Automatic service registration and name resolution
|
||||
- **Load Balancing** - Client side load balancing built on discovery
|
||||
- **Message Encoding** - Dynamic encoding based on content-type with protobuf and json support
|
||||
- **Sync Streaming** - RPC based communication with support for bidirectional streaming
|
||||
- **Async Messaging** - Native PubSub messaging built in for event driven architectures
|
||||
- **Sync Streaming** - RPC based request/response with support for bidirectional streaming
|
||||
- **Async Messaging** - Native pubsub messaging built in for event driven architectures
|
||||
|
||||
## Getting Started
|
||||
|
||||
For detailed information on the architecture, installation and use of go-micro checkout the [docs](https://micro.mu/docs).
|
||||
For detailed information on the architecture, installation and use of go-micro checkout the [docs](https://micro.mu/docs/go-micro.html).
|
||||
|
||||
## Sponsors
|
||||
|
||||
|
@@ -1,9 +1,11 @@
|
||||
// Package http provides a http based message broker
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/broker"
|
||||
)
|
||||
|
||||
// NewBroker returns a new http broker
|
||||
func NewBroker(opts ...broker.Option) broker.Broker {
|
||||
return broker.NewBroker(opts...)
|
||||
}
|
||||
|
23
broker/http/options.go
Normal file
23
broker/http/options.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/micro/go-micro/broker"
|
||||
)
|
||||
|
||||
// Handle registers the handler for the given pattern.
|
||||
func Handle(pattern string, handler http.Handler) broker.Option {
|
||||
return func(o *broker.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
handlers, ok := o.Context.Value("http_handlers").(map[string]http.Handler)
|
||||
if !ok {
|
||||
handlers = make(map[string]http.Handler)
|
||||
}
|
||||
handlers[pattern] = handler
|
||||
o.Context = context.WithValue(o.Context, "http_handlers", handlers)
|
||||
}
|
||||
}
|
@@ -18,6 +18,7 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-log"
|
||||
"github.com/micro/go-micro/broker/codec/json"
|
||||
merr "github.com/micro/go-micro/errors"
|
||||
@@ -26,7 +27,6 @@ import (
|
||||
maddr "github.com/micro/util/go/lib/addr"
|
||||
mnet "github.com/micro/util/go/lib/net"
|
||||
mls "github.com/micro/util/go/lib/tls"
|
||||
"github.com/pborman/uuid"
|
||||
)
|
||||
|
||||
// HTTP Broker is a point to point async broker
|
||||
@@ -116,7 +116,7 @@ func newHttpBroker(opts ...Option) Broker {
|
||||
}
|
||||
|
||||
h := &httpBroker{
|
||||
id: "broker-" + uuid.NewUUID().String(),
|
||||
id: "broker-" + uuid.New().String(),
|
||||
address: addr,
|
||||
opts: options,
|
||||
r: reg,
|
||||
@@ -126,7 +126,19 @@ func newHttpBroker(opts ...Option) Broker {
|
||||
mux: http.NewServeMux(),
|
||||
}
|
||||
|
||||
// specify the message handler
|
||||
h.mux.Handle(DefaultSubPath, h)
|
||||
|
||||
// get optional handlers
|
||||
if h.opts.Context != nil {
|
||||
handlers, ok := h.opts.Context.Value("http_handlers").(map[string]http.Handler)
|
||||
if ok {
|
||||
for pattern, handler := range handlers {
|
||||
h.mux.Handle(pattern, handler)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return h
|
||||
}
|
||||
|
||||
@@ -401,7 +413,7 @@ func (h *httpBroker) Init(opts ...Option) error {
|
||||
}
|
||||
|
||||
if len(h.id) == 0 {
|
||||
h.id = "broker-" + uuid.NewUUID().String()
|
||||
h.id = "broker-" + uuid.New().String()
|
||||
}
|
||||
|
||||
// get registry
|
||||
@@ -508,7 +520,7 @@ func (h *httpBroker) Subscribe(topic string, handler Handler, opts ...SubscribeO
|
||||
}
|
||||
|
||||
// create unique id
|
||||
id := h.id + "." + uuid.NewUUID().String()
|
||||
id := h.id + "." + uuid.New().String()
|
||||
|
||||
var secure bool
|
||||
|
||||
|
@@ -5,15 +5,15 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-micro/registry/mock"
|
||||
"github.com/pborman/uuid"
|
||||
)
|
||||
|
||||
func sub(be *testing.B, c int) {
|
||||
be.StopTimer()
|
||||
m := mock.NewRegistry()
|
||||
b := NewBroker(Registry(m))
|
||||
topic := uuid.NewUUID().String()
|
||||
topic := uuid.New().String()
|
||||
|
||||
if err := b.Init(); err != nil {
|
||||
be.Fatalf("Unexpected init error: %v", err)
|
||||
@@ -72,7 +72,7 @@ func pub(be *testing.B, c int) {
|
||||
be.StopTimer()
|
||||
m := mock.NewRegistry()
|
||||
b := NewBroker(Registry(m))
|
||||
topic := uuid.NewUUID().String()
|
||||
topic := uuid.New().String()
|
||||
|
||||
if err := b.Init(); err != nil {
|
||||
be.Fatalf("Unexpected init error: %v", err)
|
||||
|
@@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-micro/broker"
|
||||
"github.com/pborman/uuid"
|
||||
)
|
||||
|
||||
type mockBroker struct {
|
||||
@@ -112,7 +112,7 @@ func (m *mockBroker) Subscribe(topic string, handler broker.Handler, opts ...bro
|
||||
|
||||
sub := &mockSubscriber{
|
||||
exit: make(chan bool, 1),
|
||||
id: uuid.NewUUID().String(),
|
||||
id: uuid.New().String(),
|
||||
topic: topic,
|
||||
handler: handler,
|
||||
opts: options,
|
||||
|
@@ -1,9 +1,11 @@
|
||||
// Package rpc provides an rpc client
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/client"
|
||||
)
|
||||
|
||||
// NewClient returns a new micro client interface
|
||||
func NewClient(opts ...client.Option) client.Client {
|
||||
return client.NewClient(opts...)
|
||||
}
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// Package jsonrpc provides a json-rpc 1.0 codec
|
||||
package jsonrpc
|
||||
|
||||
import (
|
||||
|
@@ -1,3 +1,4 @@
|
||||
// Protorpc provides a net/rpc proto-rpc codec. See envelope.proto for the format.
|
||||
package protorpc
|
||||
|
||||
import (
|
||||
|
@@ -4,8 +4,8 @@ import (
|
||||
"errors"
|
||||
"sync"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-micro/server"
|
||||
"github.com/pborman/uuid"
|
||||
)
|
||||
|
||||
type MockServer struct {
|
||||
@@ -69,7 +69,7 @@ func (m *MockServer) NewHandler(h interface{}, opts ...server.HandlerOption) ser
|
||||
}
|
||||
|
||||
return &MockHandler{
|
||||
Id: uuid.NewUUID().String(),
|
||||
Id: uuid.New().String(),
|
||||
Hdlr: h,
|
||||
Opts: options,
|
||||
}
|
||||
|
@@ -1,9 +1,11 @@
|
||||
// Package rpc provides an rpc server
|
||||
package rpc
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/server"
|
||||
)
|
||||
|
||||
// NewServer returns a micro server interface
|
||||
func NewServer(opts ...server.Option) server.Server {
|
||||
return server.NewServer(opts...)
|
||||
}
|
||||
|
@@ -7,8 +7,8 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/google/uuid"
|
||||
"github.com/micro/go-log"
|
||||
"github.com/pborman/uuid"
|
||||
)
|
||||
|
||||
type Server interface {
|
||||
@@ -63,7 +63,7 @@ var (
|
||||
DefaultAddress = ":0"
|
||||
DefaultName = "go-server"
|
||||
DefaultVersion = "1.0.0"
|
||||
DefaultId = uuid.NewUUID().String()
|
||||
DefaultId = uuid.New().String()
|
||||
DefaultServer Server = newRpcServer()
|
||||
)
|
||||
|
||||
|
@@ -1,9 +1,11 @@
|
||||
// Package http returns a http2 transport using net/http
|
||||
package http
|
||||
|
||||
import (
|
||||
"github.com/micro/go-micro/transport"
|
||||
)
|
||||
|
||||
// NewTransport returns a new http transport using net/http and supporting http2
|
||||
func NewTransport(opts ...transport.Option) transport.Transport {
|
||||
return transport.NewTransport(opts...)
|
||||
}
|
||||
|
23
transport/http/options.go
Normal file
23
transport/http/options.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"github.com/micro/go-micro/transport"
|
||||
)
|
||||
|
||||
// Handle registers the handler for the given pattern.
|
||||
func Handle(pattern string, handler http.Handler) transport.Option {
|
||||
return func(o *transport.Options) {
|
||||
if o.Context == nil {
|
||||
o.Context = context.Background()
|
||||
}
|
||||
handlers, ok := o.Context.Value("http_handlers").(map[string]http.Handler)
|
||||
if !ok {
|
||||
handlers = make(map[string]http.Handler)
|
||||
}
|
||||
handlers[pattern] = handler
|
||||
o.Context = context.WithValue(o.Context, "http_handlers", handlers)
|
||||
}
|
||||
}
|
@@ -357,6 +357,8 @@ func (h *httpTransportListener) Close() error {
|
||||
func (h *httpTransportListener) Accept(fn func(Socket)) error {
|
||||
// create handler mux
|
||||
mux := http.NewServeMux()
|
||||
|
||||
// register our transport handler
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
var buf *bufio.ReadWriter
|
||||
var con net.Conn
|
||||
@@ -403,6 +405,16 @@ func (h *httpTransportListener) Accept(fn func(Socket)) error {
|
||||
})
|
||||
})
|
||||
|
||||
// get optional handlers
|
||||
if h.ht.opts.Context != nil {
|
||||
handlers, ok := h.ht.opts.Context.Value("http_handlers").(map[string]http.Handler)
|
||||
if ok {
|
||||
for pattern, handler := range handlers {
|
||||
mux.Handle(pattern, handler)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// default http2 server
|
||||
srv := &http.Server{
|
||||
Handler: mux,
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Package is an interface for synchronous communication
|
||||
// Package transport is an interface for synchronous communication
|
||||
package transport
|
||||
|
||||
import (
|
||||
|
Reference in New Issue
Block a user