41fb033d30
- Replace Axum with Chi router - Replace sqlx with pgx for PostgreSQL - Replace tonic/prost with grpc-go - Replace tracing with zerolog - Update flake.nix for Go build with protoc generation - Preserve all existing endpoints and functionality Stack: Chi, pgx, grpc-go, zerolog, yaml.v3
57 lines
1.4 KiB
Go
57 lines
1.4 KiB
Go
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,
|
|
})
|
|
}
|