This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"context" | |
uuid "github.com/satori/go.uuid" | |
) | |
// NotificatorService describes the service. | |
type NotificatorService interface { | |
// Add your methods here | |
SendEmail(ctx context.Context, email string, content string) (string, error) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (l loggingMiddleware) SendEmail(ctx context.Context, email string, content string) (string, error) { | |
defer func() { | |
l.logger.Log("method", "SendEmail", "email", email, "content", content) | |
}() | |
return l.next.SendEmail(ctx, email, content) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SendEmailResponse collects the response parameters for the SendEmail method. | |
type SendEmailResponse struct { | |
Id string | |
E0 error `json:"e0"` | |
} | |
// MakeSendEmailEndpoint returns an endpoint that invokes SendEmail on the service. | |
func MakeSendEmailEndpoint(s service.NotificatorService) endpoint.Endpoint { | |
return func(ctx context.Context, request interface{}) (interface{}, error) { | |
req := request.(SendEmailRequest) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func decodeSendEmailRequest(_ context.Context, r interface{}) (interface{}, error) { | |
req := r.(*pb.SendEmailRequest) | |
return endpoint.SendEmailRequest{Email: req.Email, Content: req.Content}, nil | |
} | |
func encodeSendEmailResponse(_ context.Context, r interface{}) (interface{}, error) { | |
reply := r.(endpoint.SendEmailResponse) | |
return &pb.SendEmailReply{Id: reply.Id}, nil | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
etcd: | |
image: 'quay.io/coreos/etcd:v3.1.7' | |
restart: always | |
ports: | |
- '23791:2379' | |
- '23801:2380' | |
environment: | |
ETCD_NAME: infra | |
ETCD_INITIAL_ADVERTISE_PEER_URLS: 'http://etcd:2380' | |
ETCD_INITIAL_CLUSTER: infra=http://etcd:2380 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
registrar, err := registerService(logger) | |
if err != nil { | |
logger.Log(err) | |
return | |
} | |
defer registrar.Deregister() | |
func registerService(logger log.Logger) (*sdetcd.Registrar, error) { | |
var ( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ( | |
"github.com/plutov/packagemain/13-go-kit-2/notificator/pkg/grpc/pb" | |
"google.golang.org/grpc" | |
) | |
type basicUsersService struct { | |
notificatorServiceClient pb.NotificatorClient | |
} | |
func (b *basicUsersService) Create(ctx context.Context, email string) error { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var etcdServer = "http://etcd:2379" | |
client, err := sdetcd.NewClient(context.Background(), []string{etcdServer}, sdetcd.ClientOptions{}) | |
if err != nil { | |
log.Printf("unable to connect to etcd: %s", err.Error()) | |
return new(basicUsersService) | |
} | |
entries, err := client.GetEntries("/services/notificator/") | |
if err != nil || len(entries) == 0 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from:(-me) {filename:vcs filename:ics} has:attachment |