-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.go
More file actions
53 lines (46 loc) · 1.07 KB
/
server.go
File metadata and controls
53 lines (46 loc) · 1.07 KB
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
43
44
45
46
47
48
49
50
51
52
53
package bb
import (
"github.com/geruz/bb/codec"
"github.com/geruz/bb/resource"
"github.com/geruz/bb/transport"
)
type Version struct {
Major int
Minor int
Patch int
}
type BBServer struct {
Name string
Version Version
codecs []codec.Codec
factories []transport.Factory
handlers []resource.Handler
}
func NewBBServer(name string, version Version) *BBServer {
server := BBServer{
Name: name,
Version: version,
}
return &server
}
func (this *BBServer) AddTransport(tr transport.Factory) {
this.factories = append(this.factories, tr)
}
func (this *BBServer) AddResource(name string, factory func() interface{}) {
this.handlers = append(this.handlers, resource.NewResourceRunner(name, factory))
}
func (this *BBServer) AddCodec(cnv codec.Codec) {
this.codecs = append(this.codecs, cnv)
}
func (this *BBServer) Loop() {
conf := transport.NewConfiguration(
this.Name,
this.Version.Major, this.Version.Major, this.Version.Patch,
this.handlers,
this.codecs,
)
for _, factory := range this.factories {
tr := factory.Create(conf)
go tr.Start()
}
}