Skip to content

Commit b42604a

Browse files
committed
手动注册服务工具使用
1 parent feb3e6e commit b42604a

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

cmd/main.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package main
2+
3+
import (
4+
"github.com/OpenIoTHub/gateway-go/v2/client"
5+
"github.com/OpenIoTHub/gateway-go/v2/register"
6+
"net"
7+
"time"
8+
)
9+
10+
func main() {
11+
client.Run()
12+
register.RegisterService("localhost-gateway-go",
13+
"_http._tcp",
14+
"local",
15+
"localhost",
16+
34323,
17+
[]string{"name=gateway-go", "home-page=https://github.com/OpenIoTHub/gateway-go"},
18+
0,
19+
[]net.IP{net.ParseIP("127.0.0.1")},
20+
[]net.IP{},
21+
)
22+
time.Sleep(500 * time.Second)
23+
}

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
client "github.com/OpenIoTHub/gateway-go/v2/client"
66
"github.com/OpenIoTHub/gateway-go/v2/config"
7+
"github.com/OpenIoTHub/gateway-go/v2/register"
78
"github.com/OpenIoTHub/gateway-go/v2/services"
89
"github.com/OpenIoTHub/gateway-go/v2/utils/login_utils"
910
"github.com/OpenIoTHub/gateway-go/v2/utils/qr"
@@ -14,6 +15,7 @@ import (
1415
"gopkg.in/yaml.v3"
1516
"io"
1617
"log"
18+
"net"
1719
"os"
1820
"sync"
1921
)
@@ -100,6 +102,16 @@ func main() {
100102
wg.Wait()
101103
return nil
102104
}
105+
register.RegisterService("localhost-gateway-go",
106+
"_http._tcp",
107+
"local",
108+
"localhost",
109+
34323,
110+
[]string{"name=gateway-go", "home-page=https://github.com/OpenIoTHub/gateway-go"},
111+
0,
112+
[]net.IP{net.ParseIP("127.0.0.1")},
113+
[]net.IP{},
114+
)
103115
err := myApp.Run(os.Args)
104116
if err != nil {
105117
log.Println(err.Error())

0 commit comments

Comments
 (0)