From: qydysky Date: Sat, 24 Aug 2024 01:18:01 +0000 (+0800) Subject: Add 添加配置ip路径 X-Git-Tag: v0.14.17~8 X-Git-Url: http://127.0.0.1:8081/?a=commitdiff_plain;h=f47e27e6e3cf1febc702350d063ee29099b84acd;p=bili_danmu%2F.git Add 添加配置ip路径 --- diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 70650b2..d910ec0 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -13,7 +13,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.22' ] + go: [ '1.23' ] steps: - name: Set up Go${{ matrix.go }} uses: actions/setup-go@v5 @@ -53,7 +53,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.22' ] + go: [ '1.23' ] steps: - name: Set up Go${{ matrix.go }} uses: actions/setup-go@v5 @@ -93,7 +93,7 @@ jobs: runs-on: windows-latest strategy: matrix: - go: [ '1.22' ] + go: [ '1.23' ] steps: - name: Set up Go${{ matrix.go }} uses: actions/setup-go@v5 @@ -133,7 +133,7 @@ jobs: runs-on: macos-latest strategy: matrix: - go: [ '1.22' ] + go: [ '1.23' ] steps: - name: Set up Go${{ matrix.go }} uses: actions/setup-go@v5 diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ded2844..bd24079 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -16,7 +16,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.22' ] + go: [ '1.23' ] steps: - name: Set up Go${{ matrix.go }} uses: actions/setup-go@v5 @@ -56,7 +56,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '1.22' ] + go: [ '1.23' ] steps: - name: Set up Go${{ matrix.go }} uses: actions/setup-go@v5 @@ -96,7 +96,7 @@ jobs: runs-on: windows-latest strategy: matrix: - go: [ '1.22' ] + go: [ '1.23' ] steps: - name: Set up Go${{ matrix.go }} uses: actions/setup-go@v5 @@ -135,7 +135,7 @@ jobs: runs-on: macos-latest strategy: matrix: - go: [ '1.22' ] + go: [ '1.23' ] steps: - name: Set up Go${{ matrix.go }} uses: actions/setup-go@v5 diff --git a/CV/Var.go b/CV/Var.go index 5fc160d..38a6550 100644 --- a/CV/Var.go +++ b/CV/Var.go @@ -30,6 +30,7 @@ import ( reqf "github.com/qydysky/part/reqf" psql "github.com/qydysky/part/sql" syncmap "github.com/qydysky/part/sync" + sys "github.com/qydysky/part/sys" web "github.com/qydysky/part/web" _ "modernc.org/sqlite" ) @@ -428,6 +429,27 @@ func (t *Common) Init() *Common { panic(e) } + port := `80` + if s := strings.Split(serAdress, ":"); len(s) > 1 { + port = s[1] + } + + var ips []string + { + // 启动时显示ip + showIpOnBoot, _ := t.K_v.LoadV("启动时显示ip").(bool) + for ip := range sys.GetIpByCidr() { + if showIpOnBoot { + if ip.To4() != nil { + fmt.Printf("当前地址 http://%s:%s\n", ip.String(), port) + } else { + fmt.Printf("当前地址 http://[%s]:%s\n", ip.String(), port) + } + } + ips = append(ips, ip.String()) + } + } + var ( readTimeout = 3 readHeaderTimeout = 3 @@ -467,6 +489,19 @@ func (t *Common) Init() *Common { } } + if val, ok := t.K_v.LoadV("ip路径").(string); ok && val != "" { + t.SerF.Store(val, func(w http.ResponseWriter, r *http.Request) { + if DefaultHttpCheck(t, w, r, http.MethodGet) { + return + } + for _, v := range ips { + if _, e := w.Write([]byte(v + "\n")); e != nil { + return + } + } + }) + } + if val, ok := t.K_v.LoadV("性能路径").(string); ok && val != "" { var cache web.Cache t.SerF.Store(val, func(w http.ResponseWriter, r *http.Request) { diff --git a/README.md b/README.md index 2c4cef3..f1df838 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,43 @@ ### 说明 本项目使用github action自动构建,构建过程详见[yml](https://github.com/qydysky/bili_danmu/blob/master/.github/workflows/go.yml) +#### ip路径 +配置文件中添加配置项`ip路径`(>v0.14.16)。不为空时,将会在指定路径显示出当前主机ip,从而可以使用主机名来获取主机ipv6,以便于[ddns-go](https://github.com/jeessy2/ddns-go)等通过命令获取ipv6。默认空。 + +例子: +``` +{ + "Web服务地址":"0.0.0.0:11000", + "ip路径":"/ip/" +} +``` + +``` +curl -s http://{主机名}:11000/ip/ +192.168.31.230 +172.16.0.1 +172.17.144.244 +172.17.0.1 +172.17.0.10 +172.17.121.35 +2409:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:8ce5 +fd55:d4a5:a9e7:0:aab8:e0ff:fe03:8ce5 +fe80::aab8:e0ff:fe03:8ce5 +fe80::d8dc:35ff:fe21:d71b +fe80::785f:8dff:fe34:9443 +fe80::440a:9fff:fe6d:5da6 +fe80::60ff:4cff:fee7:c226 +fe80::4c24:e3ff:fe65:b955 +fe80::8099:ecff:fefa:f36c +fe80::68fe:63ff:fe74:6e35 +``` + +``` +curl -s http://{主机名}:11000/ip/ | awk '/240:?/' + +2409:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:8ce5 +``` + #### 保持粉丝牌点亮 配置文件中添加配置项`保持牌子亮着_指定时间`(>v0.14.11)。将会在指定时间启动保持。默认`00:00:00` diff --git a/bili_danmu.go b/bili_danmu.go index efbbd95..55b0ba0 100644 --- a/bili_danmu.go +++ b/bili_danmu.go @@ -74,13 +74,6 @@ func Start() { } }() - // 启动时显示ip - if v, ok := c.C.K_v.LoadV("启动时显示ip").(bool); ok && v { - for _, v := range sys.GetIntranetIp(``) { - danmulog.L(`I: `, `当前ip:http://`+v) - } - } - { //如果连接中断,则等待 F.KeepConnect() diff --git a/demo/config/config_K_v.json b/demo/config/config_K_v.json index e46f2d0..7d56ca6 100644 --- a/demo/config/config_K_v.json +++ b/demo/config/config_K_v.json @@ -199,6 +199,7 @@ "debug路径":"", "性能路径-help":"当Web服务地址不为空时, 访问此路径可以获取性能信息,为空时关闭", "性能路径":"/state/", + "ip路径":"", "生成pgo-help":"将在退出后生成pgo文件在指定路径,default.pgo将有助于下次构建的优化,但会导致gc频繁,构建缓慢,为空时不生成", "生成pgo":"", "登陆二维码-白":"OO", diff --git a/go.mod b/go.mod index e38d582..f0cc28e 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.23 require ( github.com/gotk3/gotk3 v0.6.4 github.com/mdp/qrterminal/v3 v3.2.0 - github.com/qydysky/part v0.28.20240821214546 + github.com/qydysky/part v0.28.20240823183215 github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e github.com/skratchdot/open-golang v0.0.0-20200116055534-eef842397966 golang.org/x/text v0.17.0 diff --git a/go.sum b/go.sum index ec666ce..82f2b19 100644 --- a/go.sum +++ b/go.sum @@ -46,8 +46,8 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/qydysky/biliApi v0.0.0-20240725184407-15076dddb6fb h1:dtSpNF9hLQa09TUfR+xbYFkHcx2breAFsXeU7e599gE= github.com/qydysky/biliApi v0.0.0-20240725184407-15076dddb6fb/go.mod h1:om024vfxALQ5vxsbaGoMm8IS0esLYBnEOpJI8FsGoDg= -github.com/qydysky/part v0.28.20240821214546 h1:MtOxggPvVKa9t24QhxxDuIxuuSjJUCaAwVCJRsN+gWs= -github.com/qydysky/part v0.28.20240821214546/go.mod h1:lv0lIlm2keVMdwnOzXdRCUL8Ky8HoAAYw8coaBW6rb8= +github.com/qydysky/part v0.28.20240823183215 h1:irnWS/3QsVDrx8xSoFtmxkkyVPzFhnyvBFTf6mwCMpk= +github.com/qydysky/part v0.28.20240823183215/go.mod h1:lv0lIlm2keVMdwnOzXdRCUL8Ky8HoAAYw8coaBW6rb8= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=