123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- package booking
- import (
- "time"
- "github.com/go-kit/kit/log"
- shipping "github.com/longjoy/micro-go-course/section19/cargo/model"
- )
- type loggingService struct {
- logger log.Logger
- next Service
- }
- // NewLoggingService returns a new instance of a logging Service.
- func NewLoggingService(logger log.Logger, s Service) Service {
- return &loggingService{logger, s}
- }
- func (s *loggingService) BookNewCargo(origin shipping.UNLocode, destination shipping.UNLocode, deadline time.Time) (id shipping.TrackingID, err error) {
- defer func(begin time.Time) {
- s.logger.Log(
- "method", "book",
- "origin", origin,
- "destination", destination,
- "arrival_deadline", deadline,
- "took", time.Since(begin),
- "err", err,
- )
- }(time.Now())
- return s.next.BookNewCargo(origin, destination, deadline)
- }
- func (s *loggingService) LoadCargo(id shipping.TrackingID) (c Cargo, err error) {
- defer func(begin time.Time) {
- s.logger.Log(
- "method", "load",
- "tracking_id", id,
- "took", time.Since(begin),
- "err", err,
- )
- }(time.Now())
- return s.next.LoadCargo(id)
- }
- func (s *loggingService) RequestPossibleRoutesForCargo(id shipping.TrackingID) []shipping.Itinerary {
- defer func(begin time.Time) {
- s.logger.Log(
- "method", "request_routes",
- "tracking_id", id,
- "took", time.Since(begin),
- )
- }(time.Now())
- return s.next.RequestPossibleRoutesForCargo(id)
- }
- func (s *loggingService) AssignCargoToRoute(id shipping.TrackingID, itinerary shipping.Itinerary) (res bool, err error) {
- defer func(begin time.Time) {
- s.logger.Log(
- "method", "assign_to_route",
- "tracking_id", id,
- "took", time.Since(begin),
- "err", err,
- )
- }(time.Now())
- return s.next.AssignCargoToRoute(id, itinerary)
- }
- func (s *loggingService) ChangeDestination(id shipping.TrackingID, l shipping.UNLocode) (res bool, err error) {
- defer func(begin time.Time) {
- s.logger.Log(
- "method", "change_destination",
- "tracking_id", id,
- "destination", l,
- "took", time.Since(begin),
- "err", err,
- )
- }(time.Now())
- return s.next.ChangeDestination(id, l)
- }
- func (s *loggingService) Cargos() []Cargo {
- defer func(begin time.Time) {
- s.logger.Log(
- "method", "list_cargos",
- "took", time.Since(begin),
- )
- }(time.Now())
- return s.next.Cargos()
- }
- func (s *loggingService) Locations() []Location {
- defer func(begin time.Time) {
- s.logger.Log(
- "method", "list_locations",
- "took", time.Since(begin),
- )
- }(time.Now())
- return s.next.Locations()
- }
|