A universal connection dial and listen library, support tcp
and unix
with TLS
package main
import (
"context"
"github.com/yankeguo/uniconn"
)
func listen() {
cfg, err := uniconn.ParseListenURI("tcp+tls://127.0.0.1:8443?cert-file=cert.pem&key-file=key.pem")
if err != nil {
panic(err)
}
lis, err := cfg.Listen(context.Background())
if err != nil {
panic(err)
}
lis.Accept()
//...
}
func dial() {
cfg, err := uniconn.ParseDialURI("tcp+tls://127.0.0.1:8443?ca-file=ca.pem")
if err != nil {
panic(err)
}
conn, err := cfg.Dial(context.Background())
if err != nil {
panic(err)
}
defer conn.Close()
// ...
}
Listen
cert-file
: TLS certificate file path, mandatory if TLS is enabledkey-file
: TLS certificate key file path, mandatory if TLS is enabledclient-ca-file
: TLS certificate file path to client ca, setting this option will enable client authenticationkeep-alive
: TCP keep-alive period, in format of "1m", "1h", etc.multipath-tcp
: Enable multipath TCP, in format of "true" or "false"
Dial
ca-file
: TLS CA file pathcert-file
: TLS certificate file path, for client authkey-file
: TLS certificate key file path, for client authserver-name
: TLS server name, overrides connection addressinsecure
: skip tls verification
GUO YANKE, MIT License