Skip to content

Commit

Permalink
upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
IoTServ committed May 25, 2023
1 parent 0b262f7 commit 6f0fbb8
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# .github/workflows/publish.yml
name: Publish to pub.dev

on:
push:
tags:
# must align with the tag-pattern configured on pub.dev, often just replace
# with [0-9]+.[0-9]+.[0-9]+*
- 'v[0-9]+.[0-9]+.[0-9]+*' # tag-pattern on pub.dev: 'v'
# If you prefer tags like '1.2.3', without the 'v' prefix, then use:
# - '[0-9]+.[0-9]+.[0-9]+*' # tag-pattern on pub.dev: ''
# If your repository contains multiple packages consider a pattern like:
# - 'my_package_name-v[0-9]+.[0-9]+.[0-9]+*'

# Publish using the reusable workflow from dart-lang.
jobs:
publish:
uses: dart-lang/setup-dart/.github/workflows/publish.yml@v1
# with:
# working-directory: path/to/package/within/repository
57 changes: 57 additions & 0 deletions netservice/mDns_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package netservice

import (
"context"
"encoding/json"
"fmt"
"github.com/OpenIoTHub/utils/models"
"github.com/grandcat/zeroconf"
"log"
"testing"
"time"
)

func TestFindAllmDNS(t *testing.T) {
var rst = make([]*models.MDNSResult, 0)
resolver, err := zeroconf.NewResolver(nil)
if err != nil {
panic(err)
}

entries := make(chan *zeroconf.ServiceEntry)
go func(results <-chan *zeroconf.ServiceEntry) {
for entry := range results {
log.Println("entry:", entry)
//TODO 去掉记录中ip不是本网段的ip
rst = append(rst, &models.MDNSResult{
Instance: entry.Instance,
Service: entry.Service,
Domain: entry.Domain,
HostName: entry.HostName,
Port: entry.Port,
Text: entry.Text,
TTL: entry.TTL,
AddrIPv4: entry.AddrIPv4,
AddrIPv6: entry.AddrIPv6,
})
}
}(entries)
timeOut := time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeOut)
defer cancel()
err = resolver.Browse(ctx, "_services._dns-sd._udp", "local", entries)
if err != nil {
panic(err)
}
<-ctx.Done()
//log.Println("获取完成:")
//if len(rst) > 0 {
// log.Println(rst[0])
//}
rstByte, err := json.Marshal(&rst)
if err != nil {
log.Println(err.Error())
panic(err)
}
fmt.Println(string(rstByte))
}

0 comments on commit 6f0fbb8

Please sign in to comment.