2024-04-17 15:44:38 +01:00
|
|
|
package networking
|
|
|
|
|
2024-04-18 13:06:16 +01:00
|
|
|
import (
|
|
|
|
"crypto/tls"
|
2024-04-18 17:15:47 +01:00
|
|
|
"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
|
|
|
}
|
2024-04-17 15:44:38 +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())
|
2024-04-17 15:44:38 +01:00
|
|
|
if err != nil {
|
2024-04-19 02:19:22 +01:00
|
|
|
log.Panicln("Server connection error:\n",err)
|
2024-04-17 15:44:38 +01:00
|
|
|
}
|
|
|
|
conn := NewConnection[T](dialConn)
|
|
|
|
return Client[T]{Connection: conn}
|
|
|
|
}
|