messages

package
v0.0.0-...-c87944f Latest Latest
Warning

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

Go to latest
Published: May 21, 2017 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound = errors.New("user not found")
)
View Source
var StreamInterceptor = func(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error {
	return handler(srv, &Stream{ss})
}
View Source
var UnaryInterceptor = func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {

	md, ok := metadata.FromContext(ctx)
	if !ok {
		return nil, grpc.Errorf(codes.Unauthenticated, "unauthorized")
	}

	token, ok := md["authorization"]
	if !ok {
		return nil, grpc.Errorf(codes.Unauthenticated, "unauthorized")
	}

	sess, err := authClient.Auth(context.Background(), &sessions.AuthRequest{Token: []byte(token[0])})
	if err != nil {
		log.Print(err)
		return nil, grpc.Errorf(codes.Unauthenticated, err.Error())
	}

	if !sess.Status {
		return nil, grpc.Errorf(codes.Unauthenticated, "unauthorized")
	}

	return handler(ctx, req)
}

Functions

func New

func New() pb.MessageServer

Types

type ConnGetter

type ConnGetter func() redis.Conn

type Stream

type Stream struct {
	grpc.ServerStream
}

func (*Stream) Context

func (as *Stream) Context() context.Context

Jump to

Keyboard shortcuts

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