forked from ellemouton/aperture-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpricer.go
More file actions
36 lines (28 loc) · 687 Bytes
/
pricer.go
File metadata and controls
36 lines (28 loc) · 687 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package content
import (
"context"
"fmt"
"strconv"
"strings"
"github.com/lightninglabs/aperture/pricesrpc"
)
var _ pricesrpc.PricesServer = (*Server)(nil)
func (s *Server) GetPrice(ctx context.Context,
req *pricesrpc.GetPriceRequest) (*pricesrpc.GetPriceResponse, error) {
if !strings.Contains(req.Path, "quote") {
return nil, fmt.Errorf("no prices " +
"for given path")
}
id, err := strconv.Atoi(strings.TrimLeft(req.Path, "/quote/"))
if err != nil {
return nil, fmt.Errorf("could not extract id " +
"from the given path")
}
q, err := s.DB.GetQuote(id)
if err != nil {
return nil, err
}
return &pricesrpc.GetPriceResponse{
Price: q.Price,
}, nil
}