forked from IceWhaleTech/CasaOS-Installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_service.go
38 lines (32 loc) · 785 Bytes
/
api_service.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
34
35
36
37
38
package main
import (
"net"
"net/http"
"github.com/IceWhaleTech/CasaOS-Common/model"
"github.com/IceWhaleTech/CasaOS-Installer/common"
"github.com/IceWhaleTech/CasaOS-Installer/route"
"github.com/IceWhaleTech/CasaOS/service"
)
func StartAPIService() (*http.Server, chan error) {
// setup listener
listener, err := net.Listen("tcp", net.JoinHostPort(common.Localhost, "0"))
if err != nil {
panic(err)
}
// initialize routers and register at gateway
{
apiPaths := []string{
route.V2APIPath,
route.V2DocPath,
}
for _, apiPath := range apiPaths {
if err := service.MyService.Gateway().CreateRoute(&model.Route{
Path: apiPath,
Target: "http://" + listener.Addr().String(),
}); err != nil {
panic(err)
}
}
}
panic("implement me")
}