DEVELOPMENT ENVIRONMENT

~liljamo/emerwen-web

ref: 797037fe5da9b632166a17b9e7f57ec2ae0d35e3 emerwen-web/internal/client/client.go -rw-r--r-- 1.2 KiB
797037feJonni Liljamo feat: conform to new protocol changes 22 hours ago
                                                                                
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
37
38
39
40
41
42
/*
 * 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}
}