siked 7 months ago
commit
a77517820b
13 changed files with 519 additions and 0 deletions
  1. 8 0
      .idea/.gitignore
  2. 9 0
      .idea/Cold_MqttAcl.iml
  3. 14 0
      .idea/deployment.xml
  4. 8 0
      .idea/modules.xml
  5. 6 0
      .idea/vcs.xml
  6. BIN
      Cold_MqttAcl
  7. 8 0
      Z_Build.bat
  8. 4 0
      config.ini
  9. 32 0
      go.mod
  10. 128 0
      go.sum
  11. 30 0
      main.go
  12. 211 0
      routers/init.go
  13. 61 0
      routers/libString.go

+ 8 - 0
.idea/.gitignore

@@ -0,0 +1,8 @@
+# 默认忽略的文件
+/shelf/
+/workspace.xml
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
+# 基于编辑器的 HTTP 客户端请求
+/httpRequests/

+ 9 - 0
.idea/Cold_MqttAcl.iml

@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="WEB_MODULE" version="4">
+  <component name="Go" enabled="true" />
+  <component name="NewModuleRootManager">
+    <content url="file://$MODULE_DIR$" />
+    <orderEntry type="inheritedJdk" />
+    <orderEntry type="sourceFolder" forTests="false" />
+  </component>
+</module>

+ 14 - 0
.idea/deployment.xml

@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="PublishConfigData" remoteFilesAllowedToDisappearOnAutoupload="false">
+    <serverData>
+      <paths name="huitong">
+        <serverdata>
+          <mappings>
+            <mapping local="$PROJECT_DIR$" web="/" />
+          </mappings>
+        </serverdata>
+      </paths>
+    </serverData>
+  </component>
+</project>

+ 8 - 0
.idea/modules.xml

@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="ProjectModuleManager">
+    <modules>
+      <module fileurl="file://$PROJECT_DIR$/.idea/Cold_MqttAcl.iml" filepath="$PROJECT_DIR$/.idea/Cold_MqttAcl.iml" />
+    </modules>
+  </component>
+</project>

+ 6 - 0
.idea/vcs.xml

@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+  <component name="VcsDirectoryMappings">
+    <mapping directory="$PROJECT_DIR$" vcs="Git" />
+  </component>
+</project>

BIN
Cold_MqttAcl


+ 8 - 0
Z_Build.bat

@@ -0,0 +1,8 @@
+cd %~dp0
+set GOARCH=amd64
+set GOOS=linux
+set GOPATH=C:\Users\SIKED\go
+set GO111MODULE=auto
+
+
+go build -o Cold_MqttAcl main.go

+ 4 - 0
config.ini

@@ -0,0 +1,4 @@
+#服务配置
+[service]
+HttpRort=3991
+Mysql=mqtt:UQ7sPD8YZwCF2Zg!@tcp(192.168.0.88:3306)/mqtt?charset=utf8mb4&loc=Local&parseTime=True

+ 32 - 0
go.mod

@@ -0,0 +1,32 @@
+module Cold_MqttAcl
+
+go 1.19
+
+require (
+	github.com/gin-gonic/gin v1.8.2
+	github.com/jinzhu/gorm v1.9.16
+	gopkg.in/ini.v1 v1.67.0
+)
+
+require (
+	github.com/gin-contrib/sse v0.1.0 // indirect
+	github.com/go-playground/locales v0.14.0 // indirect
+	github.com/go-playground/universal-translator v0.18.0 // indirect
+	github.com/go-playground/validator/v10 v10.11.1 // indirect
+	github.com/go-sql-driver/mysql v1.5.0 // indirect
+	github.com/goccy/go-json v0.9.11 // indirect
+	github.com/jinzhu/inflection v1.0.0 // indirect
+	github.com/json-iterator/go v1.1.12 // indirect
+	github.com/leodido/go-urn v1.2.1 // indirect
+	github.com/mattn/go-isatty v0.0.16 // indirect
+	github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 // indirect
+	github.com/modern-go/reflect2 v1.0.2 // indirect
+	github.com/pelletier/go-toml/v2 v2.0.6 // indirect
+	github.com/ugorji/go/codec v1.2.7 // indirect
+	golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 // indirect
+	golang.org/x/net v0.4.0 // indirect
+	golang.org/x/sys v0.3.0 // indirect
+	golang.org/x/text v0.5.0 // indirect
+	google.golang.org/protobuf v1.28.1 // indirect
+	gopkg.in/yaml.v2 v2.4.0 // indirect
+)

+ 128 - 0
go.sum

@@ -0,0 +1,128 @@
+github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
+github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
+github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd h1:83Wprp6ROGeiHFAP8WJdI2RoxALQYgdllERc3N5N2DM=
+github.com/denisenkom/go-mssqldb v0.0.0-20191124224453-732737034ffd/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU=
+github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5 h1:Yzb9+7DPaBjB8zlTR87/ElzFsnQfuHnVUVqpZZIcV5Y=
+github.com/erikstmartin/go-testdb v0.0.0-20160219214506-8d10e4a1bae5/go.mod h1:a2zkGnVExMxdzMo3M0Hi/3sEU+cWnZpSni0O6/Yb/P0=
+github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
+github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
+github.com/gin-gonic/gin v1.8.2 h1:UzKToD9/PoFj/V4rvlKqTRKnQYyz8Sc1MJlv4JHPtvY=
+github.com/gin-gonic/gin v1.8.2/go.mod h1:qw5AYuDrzRTnhvusDsrov+fDIxp9Dleuu12h8nfB398=
+github.com/go-playground/assert/v2 v2.0.1 h1:MsBgLAaY856+nPRTKrp3/OZK38U/wa0CcBYNjji3q3A=
+github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4=
+github.com/go-playground/locales v0.14.0 h1:u50s323jtVGugKlcYeyzC0etD1HifMjqmJqb8WugfUU=
+github.com/go-playground/locales v0.14.0/go.mod h1:sawfccIbzZTqEDETgFXqTho0QybSa7l++s0DH+LDiLs=
+github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/jYrnRPArHwAcmLoJZxyho=
+github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
+github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
+github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
+github.com/go-sql-driver/mysql v1.5.0 h1:ozyZYNQW3x3HtqT1jira07DN2PArx2v7/mN66gGcHOs=
+github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
+github.com/goccy/go-json v0.9.11 h1:/pAaQDLHEoCq/5FFmSKBswWmK6H0e8g4159Kc/X/nqk=
+github.com/goccy/go-json v0.9.11/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
+github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe h1:lXe2qZdvpiX5WZkZR4hgp4KJVfY3nMkvmwbVkpv1rVY=
+github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
+github.com/jinzhu/gorm v1.9.16 h1:+IyIjPEABKRpsu/F8OvDPy9fyQlgsg2luMV2ZIH5i5o=
+github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs=
+github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
+github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
+github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M=
+github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
+github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
+github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
+github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
+github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
+github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0=
+github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
+github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
+github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
+github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
+github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
+github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
+github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
+github.com/lib/pq v1.1.1 h1:sJZmqHoEaY7f+NPP8pgLB/WxulyR3fewgCM2qaSlBb4=
+github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
+github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
+github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
+github.com/mattn/go-sqlite3 v1.14.0 h1:mLyGNKR8+Vv9CAU7PphKa2hkEqxxhn8i32J6FPj1/QA=
+github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421 h1:ZqeYNhU3OHLH3mGKHDcjJRFFRrJa6eAM5H+CtDdOsPc=
+github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
+github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
+github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
+github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
+github.com/pelletier/go-toml/v2 v2.0.6/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek=
+github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=
+github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
+github.com/rogpeppe/go-internal v1.8.0 h1:FCbCCtXNOY3UtUuHUYaghJg4y7Fd14rXifAYUAtL9R8=
+github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
+github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
+github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
+github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
+github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
+github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
+github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
+github.com/ugorji/go v1.2.7/go.mod h1:nF9osbDWLy6bDVv/Rtoh6QgnvNDpmCalQV5urGCCS6M=
+github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
+github.com/ugorji/go/codec v1.2.7/go.mod h1:WGN1fab3R1fzQlVQTkfxVtIBhWDRqOviHU95kRgeqEY=
+golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191205180655-e7c4368fe9dd/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
+golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3 h1:0es+/5331RGQPcXlMfP+WrnIIS6dNnNRe0WB02W0F4M=
+golang.org/x/crypto v0.0.0-20211215153901-e495a2d5b3d3/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
+golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
+golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
+golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
+golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
+golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
+golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
+golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
+golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20210806184541-e5e7981a1069/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
+golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
+golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
+golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
+golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
+google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
+gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
+gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
+gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA=
+gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
+gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

+ 30 - 0
main.go

@@ -0,0 +1,30 @@
+package main
+
+import (
+	"Cold_MqttAcl/routers"
+	"gopkg.in/ini.v1"
+	"log"
+)
+
+var (
+	Cfg      *ini.File
+	Mysql    string
+	HttpRort string
+)
+
+func init() {
+	var err error
+	Cfg, err = ini.Load("config.ini")
+	if err != nil {
+		log.Fatalf("Fail to parse 'config.ini': %v", err)
+	}
+	Mysql = Cfg.Section("service").Key("Mysql").String()
+	HttpRort = Cfg.Section("service").Key("HttpRort").String()
+}
+
+func main() {
+
+	//println(routers.WeekByDate() + routers.GetRandstring(10,"0123456789123456789",int64(0)))
+	routers.Gininit(HttpRort, Mysql)
+
+}

+ 211 - 0
routers/init.go

@@ -0,0 +1,211 @@
+package routers
+
+import (
+	"fmt"
+	"github.com/gin-gonic/gin"
+	"github.com/jinzhu/gorm"
+	_ "github.com/jinzhu/gorm/dialects/mysql"
+	"net/http"
+	"strings"
+)
+
+//goland:noinspection GoUnreachableCode
+func Gininit(HttpRort, Mysql string) {
+
+	r := gin.Default()
+	//"mqtt:UQ7sPD8YZwCF2Zg!@tcp(192.168.0.88:3306)/mqtt?charset=utf8mb4&loc=Local&parseTime=True"
+	db, err := gorm.Open("mysql", Mysql)
+	defer db.Close()
+	if err != nil {
+		panic(any("mysql Err!"))
+
+	}
+
+	// 开启 Logger, 以展示详细的日志
+	db.LogMode(true)
+	// 1.创建路由
+	// 2.绑定路由规则,执行的函数
+	// gin.Context,封装了request和response
+	r.POST("/CreateAuth", func(c *gin.Context) {
+		// 生产批次(数字:u32)
+		// 出库经办人编号(数字:u32)
+		// 产品防伪码(数字:u32)
+		// 产品生产时间(unix)
+		// 产品入库时间(unix)
+		// 产品出库时间(unix)
+		// SN码(文本:<=16个字符)
+		// mqtt域名/IP(文本:<=32个字符)
+		// mqtt端口(数字:1~65534)
+		// mqtt用户名(文本:<=32个字符)
+		// mqtt密码(文本:<=32个字符)
+		// mqtt保活时间(数字:30~120)
+		// mqtt消息质量(数字:0~2)
+
+		//sn := ""
+		sn := c.PostForm("sn")
+		GetRandstringI := 0
+		if len(sn) < 10 {
+			for true {
+				sn = WeekByDate() + GetRandstring(10, "0123456789123456789", int64(GetRandstringI))
+				count := 0
+
+				db.Table("mqtt_user").Where("username = ?", sn).Count(&count)
+				println("count:", count)
+				if count == 0 {
+					break
+				}
+				GetRandstringI += 1
+			}
+		} else {
+			count := 0
+			db.Table("mqtt_user").Where("username = ?", sn).Count(&count)
+			println("count:", count)
+			if count != 0 {
+				c.JSON(http.StatusOK, gin.H{"status": 201, "smg": "sn 重复!"})
+				return
+			}
+		}
+
+		psaa := GetRandstring(16, "", 1000)
+		psaa_sha256 := Sha256("salt" + psaa)
+
+		model := c.PostForm("model")
+		sver := c.PostForm("sver")
+		hver := c.PostForm("hver")
+		imei := c.PostForm("imei")
+		iccid := c.PostForm("iccid")
+
+		db_ := db.Exec(" INSERT INTO mqtt_user(username, password_hash, salt, is_superuser, model, sver, hver, imei, iccid) VALUES ('" + sn + "', '" + psaa_sha256 + "', 'salt', 0, '" + model + "', '" + sver + "', '" + hver + "', '" + imei + "', '" + iccid + "');")
+		if db_.Error != nil {
+			c.JSON(http.StatusOK, gin.H{"status": 201, "msg": db_.Error})
+			return
+		}
+
+		db_ = db.Exec(" INSERT INTO mqtt_user(username, password_hash, salt, is_superuser, model, sver, hver, imei, iccid) VALUES ('" + sn + "_s', '" + psaa_sha256 + "', 'salt', 0, '" + model + "', '" + sver + "', '" + hver + "', '" + imei + "', '" + iccid + "');")
+		if db_.Error != nil {
+			c.JSON(http.StatusOK, gin.H{"status": 201, "msg": db_.Error})
+			return
+		}
+
+		c.JSON(http.StatusOK, gin.H{"status": 200, "sn": sn, "psaa": psaa})
+		return
+	})
+	r.GET("/CreateAuth_2", func(c *gin.Context) {
+		// 生产批次(数字:u32)
+		// 出库经办人编号(数字:u32)
+		// 产品防伪码(数字:u32)
+		// 产品生产时间(unix)
+		// 产品入库时间(unix)
+		// 产品出库时间(unix)
+		// SN码(文本:<=16个字符)
+		// mqtt域名/IP(文本:<=32个字符)
+		// mqtt端口(数字:1~65534)
+		// mqtt用户名(文本:<=32个字符)
+		// mqtt密码(文本:<=32个字符)
+		// mqtt保活时间(数字:30~120)
+		// mqtt消息质量(数字:0~2)
+
+		//sn := ""
+		sn := c.Query("sn")
+
+		if len(sn) < 10 {
+			c.JSON(http.StatusOK, gin.H{"status": 201, "msg": "sn == null"})
+			return
+		}
+		//count := 0
+
+		db_ := db.Exec("DELETE FROM mqtt_user WHERE username = ?;", sn)
+		db_ = db.Exec("DELETE FROM mqtt_user WHERE username = ?;", sn+"_s")
+
+		//
+		//db.Debug().Table("mqtt_user").Where("username = ?", sn).Count(&count)
+		//println("count:",count)
+		//if count != 0 {
+		//	c.JSON(http.StatusOK, gin.H{"status": 201,"smg": "sn 重复!"})
+		//	return
+		//}
+
+		psaa := GetRandstring(16, "", 1000)
+		psaa_sha256 := Sha256("salt" + psaa)
+
+		model := c.Query("model")
+		sver := c.Query("sver")
+		hver := c.Query("hver")
+		imei := c.Query("imei")
+		iccid := c.Query("iccid")
+
+		db_ = db.Exec(" INSERT INTO mqtt_user(username, password_hash, salt, is_superuser, model, sver, hver, imei, iccid) VALUES ('" + sn + "', '" + psaa_sha256 + "', 'salt', 0, '" + model + "', '" + sver + "', '" + hver + "', '" + imei + "', '" + iccid + "');")
+		if db_.Error != nil {
+			c.JSON(http.StatusOK, gin.H{"status": 201, "msg": db_.Error})
+			return
+		}
+
+		db_ = db.Exec(" INSERT INTO mqtt_user(username, password_hash, salt, is_superuser, model, sver, hver, imei, iccid) VALUES ('" + sn + "_s', '" + psaa_sha256 + "', 'salt', 0, '" + model + "', '" + sver + "', '" + hver + "', '" + imei + "', '" + iccid + "');")
+		if db_.Error != nil {
+			c.JSON(http.StatusOK, gin.H{"status": 201, "msg": db_.Error})
+			return
+		}
+
+		c.JSON(http.StatusOK, gin.H{"status": 200, "sn": sn, "user": sn, "pass": psaa, "mqtt1": "mqttjxit.coldbaozhida.com", "mqtt2": "mqttlodr.coldbaozhida.com", "mqtt3": "mqttyuht.coldbaozhida.com", "mqtt4": "", "mqtt5": "", "port": 1883})
+		return
+	})
+
+	r.POST("/MqttAcl", func(c *gin.Context) {
+		//${clientid} — 客户端的 ID。
+		//${username} — 客户端登录是用的用户名。
+		//${peerhost} — 客户端的源 IP 地址。
+		//${proto_name} — 客户端使用的协议名称。例如 MQTT,CoAP 等。
+		//${mountpoint} — 网关监听器的挂载点(主题前缀)。
+		//${action} — 当前执行的动作请求,例如 publish,subscribe。
+		//${topic} — 当前请求想要发布或订阅的主题(或主题过滤器)
+		username := c.PostForm("username")
+		clientid := c.PostForm("clientid")
+		peerhost := c.PostForm("peerhost")
+		mountpoint := c.PostForm("mountpoint")
+		topic := c.PostForm("topic")
+		action := c.PostForm("action")
+
+		fmt.Println("username:", username)
+		fmt.Println("clientid:", clientid)
+		fmt.Println("peerhost:", peerhost)
+		fmt.Println("mountpoint:", mountpoint)
+		fmt.Println("topic:", topic)
+		fmt.Println("action:", action)
+
+		if username == "admin" {
+			c.JSON(200, gin.H{"result": "allow"})
+			return
+		}
+
+		if username == "test" {
+			c.JSON(200, gin.H{"result": "allow"})
+			return
+		}
+		//
+		if username != clientid {
+			fmt.Println("username != clientid")
+			c.JSON(200, gin.H{"result": "deny"})
+			return
+		}
+
+		//topic  /sub/SN  /pub/SN
+		topic_list := strings.Split(topic, "/")
+		if len(topic_list) < 3 {
+			fmt.Println("len(topic_list) < 3", len(topic_list))
+			c.JSON(200, gin.H{"result": "deny"})
+			return
+		}
+		Clientid_list := strings.Split(username+"_s", "_")
+		username = Clientid_list[0]
+		if topic_list[2] != username {
+			fmt.Println("topic_list[2] != username", topic_list[2])
+			c.JSON(200, gin.H{"result": "deny"})
+			return
+		}
+
+		c.JSON(200, gin.H{"result": "allow"})
+		return
+	})
+
+	r.Run(":" + HttpRort)
+}

+ 61 - 0
routers/libString.go

@@ -0,0 +1,61 @@
+package routers
+
+import (
+	"crypto/sha256"
+	"encoding/hex"
+	"fmt"
+	"math/rand"
+	"strings"
+	"time"
+)
+
+// #取得随机字符串:通过打乱slice来操作
+func GetRandstring(length int, char string, rand_x int64) string {
+	if length < 1 {
+		return ""
+	}
+
+	if len(char) <= 6 || len(char) <= length {
+		char = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
+	}
+
+	charArr := strings.Split(char, "")
+	ran := rand.New(rand.NewSource(time.Now().Unix() + rand_x))
+
+	l := len(charArr)
+	for i := l - 1; i > 0; i-- {
+		r := ran.Intn(i)
+		charArr[r], charArr[i] = charArr[i], charArr[r]
+	}
+	rchar := charArr[:length]
+	return strings.Join(rchar, "")
+}
+
+// Sha256加密
+func Sha256(src string) string {
+	m := sha256.New()
+	m.Write([]byte(src))
+	res := hex.EncodeToString(m.Sum(nil))
+	return res
+}
+
+// 判断时间是当年的第几周
+func WeekByDate() string {
+	t := time.Now()
+	yearDay := t.YearDay()
+	yearFirstDay := t.AddDate(0, 0, -yearDay+1)
+	firstDayInWeek := int(yearFirstDay.Weekday())
+
+	//今年第一周有几天
+	firstWeekDays := 1
+	if firstDayInWeek != 0 {
+		firstWeekDays = 7 - firstDayInWeek + 1
+	}
+	var week int
+	if yearDay <= firstWeekDays {
+		week = 1
+	} else {
+		week = (yearDay-firstWeekDays)/7 + 2
+	}
+	return fmt.Sprintf("%d%02d", t.Year(), week) // 202253
+}