-
Notifications
You must be signed in to change notification settings - Fork 1
/
socket.go
33 lines (27 loc) · 874 Bytes
/
socket.go
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
// Copyright (c) 2019 Meng Huang ([email protected])
// This package is licensed under a MIT license that can be found in the LICENSE file.
package rpc
import (
"crypto/tls"
"github.com/hslam/socket"
"sync"
)
var sockets = sync.Map{}
func init() {
RegisterSocket("http", socket.NewHTTPSocket)
RegisterSocket("tcp", socket.NewTCPSocket)
RegisterSocket("unix", socket.NewUNIXSocket)
RegisterSocket("ws", socket.NewWSSocket)
RegisterSocket("inproc", socket.NewINPROCSocket)
}
// RegisterSocket registers a network socket.
func RegisterSocket(network string, New func(config *tls.Config) socket.Socket) {
sockets.Store(network, New)
}
// NewSocket returns a new Socket by network.
func NewSocket(network string) func(config *tls.Config) socket.Socket {
if s, ok := sockets.Load(network); ok {
return s.(func(config *tls.Config) socket.Socket)
}
return nil
}