From c5049e2337cda43f47a22bb5102612b80cf18836 Mon Sep 17 00:00:00 2001 From: zhanli <719901725@qq.com> Date: Thu, 14 Dec 2023 11:32:04 +0800 Subject: [PATCH] update. --- Docs/创建第一个Go Web程序.md | 2 +- .../README.md | 0 .../go.mod | 0 .../go.sum | 0 .../main.go | 0 .../static/index.html | 0 .../2.Gin_Helloworld_Public_Dist/README.md | 1 + Example/2.Gin_Helloworld_Public_Dist/go.mod | 9 +++ Example/2.Gin_Helloworld_Public_Dist/go.sum | 67 +++++++++++++++++++ Example/2.Gin_Helloworld_Public_Dist/main.go | 20 ++++++ .../public/dist/index.html | 13 ++++ 11 files changed, 111 insertions(+), 1 deletion(-) rename Example/{Gin_Helloworld => 1.Gin_Helloworld}/README.md (100%) rename Example/{Gin_Helloworld => 1.Gin_Helloworld}/go.mod (100%) rename Example/{Gin_Helloworld => 1.Gin_Helloworld}/go.sum (100%) rename Example/{Gin_Helloworld => 1.Gin_Helloworld}/main.go (100%) rename Example/{Gin_Helloworld => 1.Gin_Helloworld}/static/index.html (100%) create mode 100644 Example/2.Gin_Helloworld_Public_Dist/README.md create mode 100644 Example/2.Gin_Helloworld_Public_Dist/go.mod create mode 100644 Example/2.Gin_Helloworld_Public_Dist/go.sum create mode 100644 Example/2.Gin_Helloworld_Public_Dist/main.go create mode 100644 Example/2.Gin_Helloworld_Public_Dist/public/dist/index.html diff --git a/Docs/创建第一个Go Web程序.md b/Docs/创建第一个Go Web程序.md index cfae751..203880b 100644 --- a/Docs/创建第一个Go Web程序.md +++ b/Docs/创建第一个Go Web程序.md @@ -1,4 +1,4 @@ -# 创建第一个Go Wen程序 +# 创建第一个Go Web程序 ​ 创建第一个最简单的Go Web程序,需要准备以下几个文件。`main.go`如下所示: diff --git a/Example/Gin_Helloworld/README.md b/Example/1.Gin_Helloworld/README.md similarity index 100% rename from Example/Gin_Helloworld/README.md rename to Example/1.Gin_Helloworld/README.md diff --git a/Example/Gin_Helloworld/go.mod b/Example/1.Gin_Helloworld/go.mod similarity index 100% rename from Example/Gin_Helloworld/go.mod rename to Example/1.Gin_Helloworld/go.mod diff --git a/Example/Gin_Helloworld/go.sum b/Example/1.Gin_Helloworld/go.sum similarity index 100% rename from Example/Gin_Helloworld/go.sum rename to Example/1.Gin_Helloworld/go.sum diff --git a/Example/Gin_Helloworld/main.go b/Example/1.Gin_Helloworld/main.go similarity index 100% rename from Example/Gin_Helloworld/main.go rename to Example/1.Gin_Helloworld/main.go diff --git a/Example/Gin_Helloworld/static/index.html b/Example/1.Gin_Helloworld/static/index.html similarity index 100% rename from Example/Gin_Helloworld/static/index.html rename to Example/1.Gin_Helloworld/static/index.html diff --git a/Example/2.Gin_Helloworld_Public_Dist/README.md b/Example/2.Gin_Helloworld_Public_Dist/README.md new file mode 100644 index 0000000..93a21cf --- /dev/null +++ b/Example/2.Gin_Helloworld_Public_Dist/README.md @@ -0,0 +1 @@ +在这个程序中,将静态文件`index.html`放在了`public/dist`目录,更加符合`alist`的开发结构 \ No newline at end of file diff --git a/Example/2.Gin_Helloworld_Public_Dist/go.mod b/Example/2.Gin_Helloworld_Public_Dist/go.mod new file mode 100644 index 0000000..ada7c99 --- /dev/null +++ b/Example/2.Gin_Helloworld_Public_Dist/go.mod @@ -0,0 +1,9 @@ +module example.com/myapp + +go 1.16 + +require ( + github.com/gin-gonic/gin v1.7.1 + github.com/go-sql-driver/mysql v1.6.0 + github.com/jinzhu/gorm v1.9.16 +) \ No newline at end of file diff --git a/Example/2.Gin_Helloworld_Public_Dist/go.sum b/Example/2.Gin_Helloworld_Public_Dist/go.sum new file mode 100644 index 0000000..617970d --- /dev/null +++ b/Example/2.Gin_Helloworld_Public_Dist/go.sum @@ -0,0 +1,67 @@ +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/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +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/go.mod h1:xbL0rPBG9cCiLr28tMa8zpbdarY27NDyej4t/EjAShU= +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.7.1 h1:qC89GU3p8TvKWMAVhEpmpB2CIb1hnqt2UdKZaP93mS8= +github.com/gin-gonic/gin v1.7.1/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= +github.com/go-playground/assert/v2 v2.0.1/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= +github.com/go-playground/locales v0.13.0 h1:HyWk6mgj5qFqCT5fjGBuRArbVDfE4hi8+e8ceBS/t7Q= +github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTMfnGwq/HNwmWNS8= +github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= +github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= +github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= +github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= +github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/golang-sql/civil v0.0.0-20190719163853-cb61b32ac6fe/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= +github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I= +github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw= +github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= +github.com/jinzhu/gorm v1.9.16/go.mod h1:G3LB3wezTOWM2ITLzPxEXgSkOXAntiLHS7UdBefADcs= +github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= +github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8= +github.com/json-iterator/go v1.1.9 h1:9yzud/Ht36ygwatGx56VwCZtlI/2AD15T1X2sjSuGns= +github.com/json-iterator/go v1.1.9/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4= +github.com/leodido/go-urn v1.2.0 h1:hpXL4XnriNwQ/ABnpepYM/1vCLWNDfUNts8dX3xTG6Y= +github.com/leodido/go-urn v1.2.0/go.mod h1:+8+nEpDfqqsY+g338gtMEUOtuK+4dEMhiQEgxpxOKII= +github.com/lib/pq v1.1.1/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= +github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY= +github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= +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 v0.0.0-20180701023420-4b7aa43c6742 h1:Esafd1046DLDQ0W1YjYsBW+p8U2u7vzgW2SQVmlNazg= +github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= +github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= +github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw= +github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs= +github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY= +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-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= +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/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-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd h1:xhmwyvizuTgC2qz7ZlMluP20uW+C3Rm0FD/WLDX8884= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10= +gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/Example/2.Gin_Helloworld_Public_Dist/main.go b/Example/2.Gin_Helloworld_Public_Dist/main.go new file mode 100644 index 0000000..1528d12 --- /dev/null +++ b/Example/2.Gin_Helloworld_Public_Dist/main.go @@ -0,0 +1,20 @@ +package main + +import ( + "github.com/gin-gonic/gin" +) + +func main() { + // 创建Gin引擎 + r := gin.Default() + // 设置静态文件目录 + r.Static("/static", "./public/dist/*") + + // 定义GET请求处理程序,返回HTML响应 + r.GET("/", func(c *gin.Context) { + c.File("./public/dist/index.html") + }) + + // 启动HTTP服务器 + r.Run(":8080") +} diff --git a/Example/2.Gin_Helloworld_Public_Dist/public/dist/index.html b/Example/2.Gin_Helloworld_Public_Dist/public/dist/index.html new file mode 100644 index 0000000..f690020 --- /dev/null +++ b/Example/2.Gin_Helloworld_Public_Dist/public/dist/index.html @@ -0,0 +1,13 @@ + + + + My Web Page + + + + +

Welcome to My Web Page

+

This is a paragraph of text.

+ Click here to visit Example.com + + \ No newline at end of file