Example #1
0
// VerifyToken finds a customer by authentication token.
func (s *profileServer) GetHotels(ctx context.Context, args *profile.Args) (*profile.Reply, error) {
	md, _ := metadata.FromContext(ctx)
	t := trace.Tracer{TraceID: strings.Join(md["traceID"], ",")}
	t.In(serverName, strings.Join(md["from"], ","))
	defer t.Out(strings.Join(md["from"], ","), serverName, time.Now())

	reply := new(profile.Reply)
	for _, i := range args.HotelIds {
		reply.Hotels = append(reply.Hotels, s.hotels[i])
	}

	return reply, nil
}
Example #2
0
// VerifyToken finds a customer by authentication token.
func (s *authServer) VerifyToken(ctx context.Context, args *pb.Args) (*pb.Customer, error) {
	md, _ := metadata.FromContext(ctx)

	t := trace.Tracer{TraceID: md["traceID"]}
	t.In(serverName, args.From)
	defer t.Out(args.From, serverName, time.Now())

	customer := s.customers[args.AuthToken]
	if customer == nil {
		return &pb.Customer{}, errors.New("Invalid Token")
	}

	return customer, nil
}
Example #3
0
func (c Client) GetHotels(ctx context.Context, hotelIDs []int32) ([]*pb.Hotel, error) {
	md, _ := metadata.FromContext(ctx)
	t := trace.Tracer{TraceID: md["traceID"]}
	t.Req(md["from"], "service.profile", "GetHotels")
	defer t.Rep("service.profile", md["from"], time.Now())

	args := &pb.Args{HotelIds: hotelIDs}
	reply, err := c.client.GetHotels(ctx, args)

	if err != nil {
		return []*pb.Hotel{}, err
	}

	return reply.Hotels, nil
}
Example #4
0
// BoundedBox returns all hotels contained within a given rectangle.
func (s *geoServer) BoundedBox(ctx context.Context, rect *pb.Rectangle) (*pb.Reply, error) {
	md, _ := metadata.FromContext(ctx)
	t := trace.Tracer{TraceID: md["traceID"]}
	t.In(serverName, md["from"])
	defer t.Out(md["from"], serverName, time.Now())

	reply := new(pb.Reply)
	for _, loc := range s.locations {
		if inRange(loc.Point, rect) {
			reply.HotelIds = append(reply.HotelIds, loc.HotelID)
		}
	}

	return reply, nil
}
Example #5
0
// VerifyToken finds a customer by authentication token.
func (s *profileServer) GetProfiles(ctx context.Context, args *profile.ProfileRequest) (*profile.ProfileReply, error) {
	md, _ := metadata.FromContext(ctx)
	traceID := strings.Join(md["traceID"], ",")
	fromName := strings.Join(md["fromName"], ",")

	t := trace.Tracer{TraceID: traceID}
	t.In(s.serverName, fromName)
	defer t.Out(fromName, s.serverName, time.Now())

	reply := new(profile.ProfileReply)
	for _, i := range args.HotelIds {
		reply.Hotels = append(reply.Hotels, s.hotels[i])
	}

	return reply, nil
}
Example #6
0
// GetRates gets rates for hotels for specific date range.
func (s *rateServer) GetRates(ctx context.Context, args *pb.Args) (*pb.Reply, error) {
	md, _ := metadata.FromContext(ctx)
	t := trace.Tracer{TraceID: md["traceID"]}
	t.In(serverName, md["from"])
	defer t.Out(md["from"], serverName, time.Now())

	reply := new(pb.Reply)
	for _, hotelID := range args.HotelIds {
		k := stay{hotelID, args.InDate, args.OutDate}
		if s.rates[k] == nil {
			continue
		}
		reply.RatePlans = append(reply.RatePlans, s.rates[k])
	}

	return reply, nil
}
Example #7
0
func (c Client) VerifyToken(ctx context.Context, serverName string, authToken string) error {
	md, _ := metadata.FromContext(ctx)
	t := trace.Tracer{TraceID: md["traceID"]}
	t.Req(md["from"], "service.auth", "VerifyToken")
	defer t.Rep("service.auth", md["from"], time.Now())

	args := &auth.Args{
		From:      serverName,
		AuthToken: authToken,
	}

	if _, err := c.client.VerifyToken(ctx, args); err != nil {
		return err
	}

	return nil
}
Example #8
0
// BoundedBox returns all hotels contained within a given rectangle.
func (s *geoServer) BoundedBox(ctx context.Context, rect *geo.GeoRequest) (*geo.GeoReply, error) {
	md, _ := metadata.FromContext(ctx)
	traceID := strings.Join(md["traceID"], ",")
	fromName := strings.Join(md["fromName"], ",")

	t := trace.Tracer{TraceID: traceID}
	t.In(s.serverName, fromName)
	defer t.Out(fromName, s.serverName, time.Now())

	reply := new(geo.GeoReply)
	for _, loc := range s.locations {
		if inRange(loc.Point, rect) {
			reply.HotelIds = append(reply.HotelIds, loc.HotelID)
		}
	}

	return reply, nil
}
Example #9
0
// VerifyToken finds a customer by authentication token.
func (s *authServer) VerifyToken(ctx context.Context, args *auth.AuthRequest) (*auth.AuthReply, error) {
	md, _ := metadata.FromContext(ctx)
	traceID := strings.Join(md["traceID"], ",")
	fromName := strings.Join(md["fromName"], ",")

	t := trace.Tracer{TraceID: traceID}
	t.In(s.serverName, fromName)
	defer t.Out(fromName, s.serverName, time.Now())

	customer := s.customers[args.AuthToken]
	if customer == nil {
		return &auth.AuthReply{}, errors.New("Invalid Token")
	}

	reply := new(auth.AuthReply)
	reply.Customer = customer
	return reply, nil
}
Example #10
0
func (c Client) GetRatePlans(ctx context.Context, hotelIDs []int32, inDate string, outDate string) ([]*pb.RatePlan, error) {
	md, _ := metadata.FromContext(ctx)
	t := trace.Tracer{TraceID: md["traceID"]}
	t.Req(md["from"], "service.rate", "GetRatePlans")
	defer t.Rep("service.rate", md["from"], time.Now())

	args := &pb.Args{
		HotelIds: hotelIDs,
		InDate:   inDate,
		OutDate:  outDate,
	}

	reply, err := c.client.GetRates(ctx, args)
	if err != nil {
		return []*pb.RatePlan{}, err
	}

	return reply.RatePlans, nil
}
Example #11
0
func (c Client) HotelsWithinBoundedBox(ctx context.Context, latitude int32, longitude int32) ([]int32, error) {
	md, _ := metadata.FromContext(ctx)
	t := trace.Tracer{TraceID: md["traceID"]}
	t.Req(md["from"], "service.geo", "BoundedBox")
	defer t.Rep("service.geo", md["from"], time.Now())

	rect := &pb.Rectangle{
		Lo: &pb.Point{Latitude: 400000000, Longitude: -750000000},
		Hi: &pb.Point{Latitude: 420000000, Longitude: -730000000},
	}

	reply, err := c.client.BoundedBox(ctx, rect)

	if err != nil {
		return []int32{}, err
	}

	return reply.HotelIds, nil
}
Example #12
0
// GetRates gets rates for hotels for specific date range.
func (s *rateServer) GetRates(ctx context.Context, args *rate.RateRequest) (*rate.RateReply, error) {
	md, _ := metadata.FromContext(ctx)
	traceID := strings.Join(md["traceID"], ",")
	fromName := strings.Join(md["fromName"], ",")

	t := trace.Tracer{TraceID: traceID}
	t.In(s.serverName, fromName)
	defer t.Out(fromName, s.serverName, time.Now())

	reply := new(rate.RateReply)
	for _, hotelID := range args.HotelIds {
		k := stay{hotelID, args.InDate, args.OutDate}
		if s.rates[k] == nil {
			continue
		}
		reply.RatePlans = append(reply.RatePlans, s.rates[k])
	}

	return reply, nil
}