Skip to content

Commit

Permalink
fix binary building
Browse files Browse the repository at this point in the history
  • Loading branch information
crazybber committed May 19, 2021
1 parent a87a0eb commit 64e7cd8
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 60 deletions.
46 changes: 4 additions & 42 deletions service/broker/handler/handler.go
Original file line number Diff line number Diff line change
@@ -1,58 +1,20 @@
package broker
package handler

import (
"context"
"time"

pbBroker "github.com/micro-community/micro/v3/proto/broker"
"github.com/micro-community/micro/v3/service"
"github.com/micro-community/micro/v3/service/auth"
"github.com/micro-community/micro/v3/service/broker"
"github.com/micro-community/micro/v3/service/context/metadata"
"github.com/micro-community/micro/v3/service/errors"
"github.com/micro-community/micro/v3/service/logger"
inAuthNamespace "github.com/micro-community/micro/v3/util/auth/namespace"
"github.com/urfave/cli/v2"
)

var (
name = "broker"
address = ":8003"
)

// Run the micro broker
func Run(ctx *cli.Context) error {
srvOpts := []service.Option{
service.Name(name),
service.Address(address),
}

if i := time.Duration(ctx.Int("register_ttl")); i > 0 {
srvOpts = append(srvOpts, service.RegisterTTL(i*time.Second))
}
if i := time.Duration(ctx.Int("register_interval")); i > 0 {
srvOpts = append(srvOpts, service.RegisterInterval(i*time.Second))
}

// new service
srv := service.New(srvOpts...)

// connect to the broker
broker.DefaultBroker.Connect()

// register the broker handler
pbBroker.RegisterBrokerHandler(srv.Server(), new(handler))

// run the service
if err := srv.Run(); err != nil {
logger.Fatal(err)
}
return nil
}

type handler struct{}
type Broker struct{}

func (h *handler) Publish(ctx context.Context, req *pbBroker.PublishRequest, rsp *pbBroker.Empty) error {
func (h *Broker) Publish(ctx context.Context, req *pbBroker.PublishRequest, rsp *pbBroker.Empty) error {
// authorize the request
acc, ok := auth.AccountFromContext(ctx)
if !ok {
Expand Down Expand Up @@ -90,7 +52,7 @@ func (h *handler) Publish(ctx context.Context, req *pbBroker.PublishRequest, rsp
return nil
}

func (h *handler) Subscribe(ctx context.Context, req *pbBroker.SubscribeRequest, stream pbBroker.Broker_SubscribeStream) error {
func (h *Broker) Subscribe(ctx context.Context, req *pbBroker.SubscribeRequest, stream pbBroker.Broker_SubscribeStream) error {
// authorize the request
acc, ok := auth.AccountFromContext(ctx)
if !ok {
Expand Down
5 changes: 3 additions & 2 deletions service/config/server/server.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package config
package server

import (
pb "github.com/micro-community/micro/v3/proto/config"
"github.com/micro-community/micro/v3/service"
"github.com/micro-community/micro/v3/service/config/handler"
"github.com/micro-community/micro/v3/service/logger"
"github.com/micro-community/micro/v3/service/store"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -34,7 +35,7 @@ func Run(c *cli.Context) error {
store.DefaultStore.Init(store.Table("config"))

// register the handler
pb.RegisterConfigHandler(srv.Server(), NewConfig(c.String("config_secret_key")))
pb.RegisterConfigHandler(srv.Server(), handler.NewConfig(c.String("config_secret_key")))
// register the subscriber
//srv.Subscribe(watchTopic, new(watcher))

Expand Down
7 changes: 4 additions & 3 deletions service/events/server/server.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package events
package server

import (
pb "github.com/micro-community/micro/v3/proto/events"
"github.com/micro-community/micro/v3/service"
"github.com/micro-community/micro/v3/service/events/handler"
"github.com/micro-community/micro/v3/service/logger"
"github.com/urfave/cli/v2"
)
Expand All @@ -15,8 +16,8 @@ func Run(ctx *cli.Context) error {
)

// register the handlers
pb.RegisterStreamHandler(srv.Server(), new(Stream))
pb.RegisterStoreHandler(srv.Server(), new(Store))
pb.RegisterStreamHandler(srv.Server(), new(handler.Stream))
pb.RegisterStoreHandler(srv.Server(), new(handler.Store))

// run the service
if err := srv.Run(); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions service/network/handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
pb "github.com/micro-community/micro/v3/proto/network"
pbRtr "github.com/micro-community/micro/v3/proto/router"
"github.com/micro-community/micro/v3/service/errors"
log "github.com/micro-community/micro/v3/service/logger"
"github.com/micro-community/micro/v3/service/logger"
"github.com/micro-community/micro/v3/service/network"
"github.com/micro-community/micro/v3/service/network/mucp"
"github.com/micro-community/micro/v3/service/network/util"
Expand Down Expand Up @@ -83,7 +83,7 @@ func (n *Network) Connect(ctx context.Context, req *pb.ConnectRequest, resp *pb.
nodes = append(nodes, node.Address)
}

log.Infof("Network.Connect setting peers: %v", nodes)
logger.Infof("Network.Connect setting peers: %v", nodes)

// reinitialize the peers
n.Network.Init(
Expand Down
13 changes: 7 additions & 6 deletions service/network/server/server.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package network
package server

import (
"errors"
Expand All @@ -10,7 +10,12 @@ import (
"github.com/micro-community/micro/v3/service"
log "github.com/micro-community/micro/v3/service/logger"
net "github.com/micro-community/micro/v3/service/network"
"github.com/micro-community/micro/v3/service/network/handler"
"github.com/micro-community/micro/v3/service/network/mucp"
"github.com/micro-community/micro/v3/service/network/transport"
"github.com/micro-community/micro/v3/service/network/transport/grpc"
"github.com/micro-community/micro/v3/service/network/tunnel"
tmucp "github.com/micro-community/micro/v3/service/network/tunnel/mucp"
"github.com/micro-community/micro/v3/service/proxy"
grpcProxy "github.com/micro-community/micro/v3/service/proxy/grpc"
mucpProxy "github.com/micro-community/micro/v3/service/proxy/mucp"
Expand All @@ -19,10 +24,6 @@ import (
mucpServer "github.com/micro-community/micro/v3/service/server/mucp"
"github.com/micro-community/micro/v3/util/helper"
"github.com/micro-community/micro/v3/util/muxer"
"github.com/micro-community/micro/v3/service/network/transport"
"github.com/micro-community/micro/v3/service/network/transport/grpc"
"github.com/micro-community/micro/v3/service/network/tunnel"
tmucp "github.com/micro-community/micro/v3/service/network/tunnel/mucp"
"github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -169,7 +170,7 @@ func Run(ctx *cli.Context) error {

// create a handler
h := mucpServer.DefaultRouter.NewHandler(
&Network{Network: netService},
&handler.Network{Network: netService},
)

// register the handler
Expand Down
12 changes: 7 additions & 5 deletions service/store/server/server.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package server

import (
"log"

pb "github.com/micro-community/micro/v3/proto/store"
"github.com/micro-community/micro/v3/service"
"github.com/micro-community/micro/v3/service/logger"
"github.com/micro-community/micro/v3/service/store/handler"
"github.com/urfave/cli/v2"
)

Expand All @@ -30,16 +32,16 @@ func Run(ctx *cli.Context) error {
)

// the store handler
pb.RegisterStoreHandler(service.Server(), &handler{
stores: make(map[string]bool),
pb.RegisterStoreHandler(service.Server(), &handler.Store{
Stores: make(map[string]bool),
})

// the blob store handler
pb.RegisterBlobStoreHandler(service.Server(), new(blobHandler))
pb.RegisterBlobStoreHandler(service.Server(), new(handler.BlobStore))

// start the service
if err := service.Run(); err != nil {
logger.Fatal(err)
log.Fatal(err)
}
return nil
}

0 comments on commit 64e7cd8

Please sign in to comment.