CSI-ES-2324/Projs/PD1/internal/utils/networking/client.go

25 lines
524 B
Go
Raw Normal View History

package networking
2024-04-18 13:06:16 +01:00
import (
"crypto/tls"
"log"
2024-04-18 13:06:16 +01:00
)
type ClientTLSConfigProvider interface {
2024-04-19 02:19:22 +01:00
GetClientTLSConfig() *tls.Config
2024-04-18 13:06:16 +01:00
}
type Client[T any] struct {
Connection Connection[T]
}
2024-04-18 13:06:16 +01:00
func NewClient[T any](clientTLSConfigProvider ClientTLSConfigProvider) Client[T] {
2024-04-19 02:19:22 +01:00
dialConn, err := tls.Dial("tcp", "localhost:8080", clientTLSConfigProvider.GetClientTLSConfig())
if err != nil {
2024-04-19 02:19:22 +01:00
log.Panicln("Server connection error:\n",err)
}
conn := NewConnection[T](dialConn)
return Client[T]{Connection: conn}
}