/*
* Copyright (C) 2024 Jonni Liljamo <jonni@liljamo.com>
*
* This file is licensed under GPL-3.0-or-later, see NOTICE and LICENSE for
* more information.
*/
// Package client provides a type wrapper for the emerwen gRPC WebToMasterClient.
package client
import (
"context"
"fmt"
"log/slog"
"git.src.quest/~liljamo/emerwen-proto/go/proto"
"git.src.quest/~liljamo/emerwen-web/internal/config"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/metadata"
)
// Client wraps the emerwen gRPC CoordinatorControlServiceClient, along with a Context.
type Client struct {
Client proto.CoordinatorControlServiceClient
Ctx context.Context
}
// NewClient constructs a new Client.
func NewClient(c *config.Config) *Client {
conn, err := grpc.NewClient(fmt.Sprintf("unix://%s", c.SocketPath), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
slog.Error("yay")
}
client := proto.NewCoordinatorControlServiceClient(conn)
// TODO: config read auth_token from file
ctx := metadata.AppendToOutgoingContext(context.Background(), "authorization", "Bearer avain_perkele")
return &Client{Client: client, Ctx: ctx}
}