Start from the beginning
This commit is contained in:
@@ -1,56 +0,0 @@
|
||||
package metadata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
pb "github.com/fujin/music-agregator/pkg/metadatapb/metadata/v1"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials/insecure"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
conn *grpc.ClientConn
|
||||
client pb.MetadataServiceClient
|
||||
}
|
||||
|
||||
func NewClient(endpoint string) (*Client, error) {
|
||||
endpoint = strings.TrimPrefix(endpoint, "http://")
|
||||
endpoint = strings.TrimPrefix(endpoint, "https://")
|
||||
|
||||
conn, err := grpc.NewClient(endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Client{
|
||||
conn: conn,
|
||||
client: pb.NewMetadataServiceClient(conn),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (c *Client) Close() error {
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
func (c *Client) SearchArtists(ctx context.Context, query string, limit, offset int32) (*pb.SearchArtistsResponse, error) {
|
||||
return c.client.SearchArtists(ctx, &pb.SearchArtistsRequest{
|
||||
Query: query,
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Client) GetArtist(ctx context.Context, id string) (*pb.Artist, error) {
|
||||
return c.client.GetArtist(ctx, &pb.GetArtistRequest{
|
||||
Identifier: &pb.GetArtistRequest_Id{Id: id},
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Client) GetArtistAlbums(ctx context.Context, artistID string, limit, offset int32) (*pb.GetArtistAlbumsResponse, error) {
|
||||
return c.client.GetArtistAlbums(ctx, &pb.GetArtistAlbumsRequest{
|
||||
ArtistId: artistID,
|
||||
Limit: limit,
|
||||
Offset: offset,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user