From e8d42e0957095a77d72e9d4cdf57d95d1714dba0 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 28 Sep 2024 00:43:57 +0800 Subject: [PATCH 01/11] chore: update dependencies and Go version to latest releases - Update Go version from 1.18 to 1.21.0 - Upgrade `github.com/gin-gonic/gin` from v1.9.1 to v1.10.0 - Upgrade `github.com/bytedance/sonic` from v1.11.6 to v1.12.3 - Upgrade `github.com/bytedance/sonic/loader` from v0.1.1 to v0.2.0 - Upgrade `github.com/gabriel-vasile/mimetype` from v1.4.3 to v1.4.5 - Upgrade `github.com/go-playground/validator/v10` from v10.20.0 to v10.22.1 - Upgrade `github.com/goccy/go-json` from v0.10.2 to v0.10.3 - Upgrade `github.com/klauspost/cpuid/v2` from v2.2.7 to v2.2.8 - Upgrade `github.com/pelletier/go-toml/v2` from v2.2.2 to v2.2.3 - Upgrade `golang.org/x/arch` from v0.8.0 to v0.10.0 - Upgrade `golang.org/x/crypto` from v0.22.0 to v0.27.0 - Upgrade `golang.org/x/net` from v0.24.0 to v0.29.0 - Upgrade `golang.org/x/sys` from v0.20.0 to v0.25.0 - Upgrade `golang.org/x/text` from v0.15.0 to v0.18.0 - Upgrade `google.golang.org/protobuf` from v1.34.0 to v1.34.2 Signed-off-by: appleboy --- go.mod | 30 ++++++++++++++-------------- go.sum | 62 +++++++++++++++++++++++++++++----------------------------- 2 files changed, 46 insertions(+), 46 deletions(-) diff --git a/go.mod b/go.mod index 2b1ce3c..474526b 100644 --- a/go.mod +++ b/go.mod @@ -1,39 +1,39 @@ module github.com/gin-contrib/multitemplate -go 1.18 +go 1.21.0 require ( - github.com/gin-gonic/gin v1.9.1 + github.com/gin-gonic/gin v1.10.0 github.com/stretchr/testify v1.9.0 ) require ( - github.com/bytedance/sonic v1.11.6 // indirect - github.com/bytedance/sonic/loader v0.1.1 // indirect + github.com/bytedance/sonic v1.12.3 // indirect + github.com/bytedance/sonic/loader v0.2.0 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.3 // indirect + github.com/gabriel-vasile/mimetype v1.4.5 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.20.0 // indirect - github.com/goccy/go-json v0.10.2 // indirect + github.com/go-playground/validator/v10 v10.22.1 // indirect + github.com/goccy/go-json v0.10.3 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.7 // indirect + github.com/klauspost/cpuid/v2 v2.2.8 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect - github.com/pelletier/go-toml/v2 v2.2.2 // indirect + github.com/pelletier/go-toml/v2 v2.2.3 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect - golang.org/x/arch v0.8.0 // indirect - golang.org/x/crypto v0.22.0 // indirect - golang.org/x/net v0.24.0 // indirect - golang.org/x/sys v0.20.0 // indirect - golang.org/x/text v0.15.0 // indirect - google.golang.org/protobuf v1.34.0 // indirect + golang.org/x/arch v0.10.0 // indirect + golang.org/x/crypto v0.27.0 // indirect + golang.org/x/net v0.29.0 // indirect + golang.org/x/sys v0.25.0 // indirect + golang.org/x/text v0.18.0 // indirect + google.golang.org/protobuf v1.34.2 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index a721f8a..c9e9375 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,8 @@ -github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= -github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= -github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= +github.com/bytedance/sonic v1.12.3 h1:W2MGa7RCU1QTeYRTPE3+88mVC0yXmsRQRChiyVocVjU= +github.com/bytedance/sonic v1.12.3/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM= +github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= @@ -9,28 +10,30 @@ github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQ 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/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= +github.com/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4= +github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4= 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.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= -github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= +github.com/gin-gonic/gin v1.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= +github.com/gin-gonic/gin v1.10.0/go.mod h1:4PMNQiOhvDRa013RKVbsiNwoyezlm2rm0uX/T7kzp5Y= github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= +github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= -github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= -github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= -github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= +github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= +github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= +github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= 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/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.7 h1:ZWSB3igEs+d0qvnxR/ZBzXVmxkgt8DdzP6m9pfuVLDM= -github.com/klauspost/cpuid/v2 v2.2.7/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= +github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= @@ -41,46 +44,43 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/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.2.2 h1:aYUidT7k73Pcl9nb2gScu7NSrKCSHIDE89b3+6Wq+LM= -github.com/pelletier/go-toml/v2 v2.2.2/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs= +github.com/pelletier/go-toml/v2 v2.2.3 h1:YmeHyLY8mFWbdkNWwpr+qIL2bEqT0o95WSdkNHvL12M= +github.com/pelletier/go-toml/v2 v2.2.3/go.mod h1:MfCQTFTvCcUyyvvwm1+G6H/jORL20Xlb6rzQu9GuUkc= 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/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/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= 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/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS4MhqMhdFk5YI= github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc= -golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/arch v0.10.0 h1:S3huipmSclq3PJMNe76NGwkBR504WFkQ5dhzWzP8ZW8= +golang.org/x/arch v0.10.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y= -golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= +golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= +golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= -google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= -google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= +google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/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= nullprogram.com/x/optparse v1.0.0/go.mod h1:KdyPE+Igbe0jQUrVfMqDMeJQIJZEuyV7pjYmp6pbG50= -rsc.io/pdf v0.1.1/go.mod h1:n8OzWcQ6Sp37PL01nO98y4iUCRdTGarVfzxY20ICaU4= From 022982a424b68c2378fbaa6a3cd774f9b5461496 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 28 Sep 2024 00:44:05 +0800 Subject: [PATCH 02/11] ci: update Go versions and remove macOS build cache config - Update Go versions to test only 1.21, 1.22, and 1.23 - Remove macOS build cache configuration Signed-off-by: appleboy --- .github/workflows/go.yml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index b3e8d89..caaf0aa 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -30,12 +30,10 @@ jobs: strategy: matrix: os: [ubuntu-latest] - go: [1.18, 1.19, "1.20", 1.21, 1.22] + go: [1.21, 1.22, 1.23] include: - os: ubuntu-latest go-build: ~/.cache/go-build - - os: macos-latest - go-build: ~/Library/Caches/go-build name: ${{ matrix.os }} @ Go ${{ matrix.go }} runs-on: ${{ matrix.os }} env: From bb7ab1d46886e6bc85f152a04be72894f044b9f0 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 28 Sep 2024 00:44:23 +0800 Subject: [PATCH 03/11] ci: update GoReleaser action to version 6 - Update GoReleaser action from version 5 to version 6 Signed-off-by: appleboy --- .github/workflows/goreleaser.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/goreleaser.yml b/.github/workflows/goreleaser.yml index 0392c49..b00b7a0 100644 --- a/.github/workflows/goreleaser.yml +++ b/.github/workflows/goreleaser.yml @@ -23,7 +23,7 @@ jobs: go-version-file: go.mod check-latest: true - name: Run GoReleaser - uses: goreleaser/goreleaser-action@v5 + uses: goreleaser/goreleaser-action@v6 with: # either 'goreleaser' (default) or 'goreleaser-pro' distribution: goreleaser From d2d77df0d44b2389be743b943f9b03ed8eb0e9ab Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 28 Sep 2024 00:54:03 +0800 Subject: [PATCH 04/11] refactor: refactor template handling and request functions - Add `.golangci.yml` configuration file with specific linters enabled and a 3-minute timeout. - Refactor `AddFromStringsFuncs` method signature in `dynamic.go` and `multitemplate.go` for better readability. - Update `performRequest` function to remove method and path parameters, defaulting to `GET` and `/`. - Modify `createFromStringsWithFuncsDynamic` and `createFromStringsWithFuncs` tests to use the new `AddFromStringsFuncs` method signature. - Simplify `performRequest` calls in multiple test functions by removing redundant parameters. - Adjust template loading logic in `example/advanced/example.go` and `example/multibase/example.go` to use `layoutCopy` directly. Signed-off-by: appleboy --- .golangci.yml | 39 ++++++++++++++++++++++++++++++++++++ dynamic.go | 6 +++++- dynamic_test.go | 18 ++++++++++------- example/advanced/example.go | 4 ++-- example/multibase/example.go | 8 ++++---- multitemplate.go | 6 +++++- multitemplate_test.go | 22 +++++++++++--------- 7 files changed, 79 insertions(+), 24 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..d59c99b --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,39 @@ +linters: + enable-all: false + disable-all: true + fast: false + enable: + - bodyclose + - dogsled + - dupl + - errcheck + - exportloopref + - exhaustive + - gochecknoinits + - goconst + - gocritic + - gocyclo + - gofmt + - goimports + - goprintffuncname + - gosec + - gosimple + - govet + - ineffassign + - lll + - misspell + - nakedret + - noctx + - nolintlint + - rowserrcheck + - staticcheck + - stylecheck + - typecheck + - unconvert + - unparam + - unused + - whitespace + - gofumpt + +run: + timeout: 3m diff --git a/dynamic.go b/dynamic.go index 0642d50..a272c70 100644 --- a/dynamic.go +++ b/dynamic.go @@ -129,7 +129,11 @@ func (r DynamicRender) AddFromString(name, templateString string) *template.Temp } // AddFromStringsFuncs supply add template from strings -func (r DynamicRender) AddFromStringsFuncs(name string, funcMap template.FuncMap, templateStrings ...string) *template.Template { +func (r DynamicRender) AddFromStringsFuncs( + name string, + funcMap template.FuncMap, + templateStrings ...string, +) *template.Template { builder := &templateBuilder{ templateName: name, funcMap: funcMap, templateStrings: templateStrings, diff --git a/dynamic_test.go b/dynamic_test.go index 0a2cefa..ef001ca 100644 --- a/dynamic_test.go +++ b/dynamic_test.go @@ -39,7 +39,11 @@ func createFromStringDynamic() Renderer { func createFromStringsWithFuncsDynamic() Renderer { r := NewRenderer() - r.AddFromStringsFuncs("index", template.FuncMap{}, `Welcome to {{ .name }} {{template "content"}}`, `{{define "content"}}template{{end}}`) + r.AddFromStringsFuncs( + "index", + template.FuncMap{}, + `Welcome to {{ .name }} {{template "content"}}`, `{{define "content"}}template{{end}}`, + ) return r } @@ -79,7 +83,7 @@ func TestAddFromFilesDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) } @@ -93,7 +97,7 @@ func TestAddFromGlobDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is login template\n", w.Body.String()) } @@ -107,7 +111,7 @@ func TestAddFromFSDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) } @@ -121,7 +125,7 @@ func TestAddFromStringDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template", w.Body.String()) } @@ -135,7 +139,7 @@ func TestAddFromStringsFruncsDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template", w.Body.String()) } @@ -149,7 +153,7 @@ func TestAddFromFilesFruncsDynamic(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template\n", w.Body.String()) } diff --git a/example/advanced/example.go b/example/advanced/example.go index 9465850..0467537 100644 --- a/example/advanced/example.go +++ b/example/advanced/example.go @@ -44,8 +44,8 @@ func loadTemplates(templatesDir string) multitemplate.Renderer { for _, include := range includes { layoutCopy := make([]string, len(layouts)) copy(layoutCopy, layouts) - files := append(layoutCopy, include) - r.AddFromFiles(filepath.Base(include), files...) + layoutCopy = append(layoutCopy, include) + r.AddFromFiles(filepath.Base(include), layoutCopy...) } return r } diff --git a/example/multibase/example.go b/example/multibase/example.go index 2a5d743..f2df977 100644 --- a/example/multibase/example.go +++ b/example/multibase/example.go @@ -44,8 +44,8 @@ func loadTemplates(templatesDir string) multitemplate.Renderer { for _, article := range articles { layoutCopy := make([]string, len(articleLayouts)) copy(layoutCopy, articleLayouts) - files := append(layoutCopy, article) - r.AddFromFiles(filepath.Base(article), files...) + layoutCopy = append(layoutCopy, article) + r.AddFromFiles(filepath.Base(article), layoutCopy...) } adminLayouts, err := filepath.Glob(templatesDir + "/layouts/admin-base.html") @@ -62,8 +62,8 @@ func loadTemplates(templatesDir string) multitemplate.Renderer { for _, admin := range admins { layoutCopy := make([]string, len(adminLayouts)) copy(layoutCopy, adminLayouts) - files := append(layoutCopy, admin) - r.AddFromFiles(filepath.Base(admin), files...) + layoutCopy = append(layoutCopy, admin) + r.AddFromFiles(filepath.Base(admin), layoutCopy...) } return r } diff --git a/multitemplate.go b/multitemplate.go index 09c2978..94937b6 100644 --- a/multitemplate.go +++ b/multitemplate.go @@ -65,7 +65,11 @@ func (r Render) AddFromString(name, templateString string) *template.Template { } // AddFromStringsFuncs supply add template from strings -func (r Render) AddFromStringsFuncs(name string, funcMap template.FuncMap, templateStrings ...string) *template.Template { +func (r Render) AddFromStringsFuncs( + name string, + funcMap template.FuncMap, + templateStrings ...string, +) *template.Template { tmpl := template.New(name).Funcs(funcMap) for _, ts := range templateStrings { diff --git a/multitemplate_test.go b/multitemplate_test.go index 6b631de..f0d2854 100644 --- a/multitemplate_test.go +++ b/multitemplate_test.go @@ -12,8 +12,8 @@ import ( "github.com/stretchr/testify/assert" ) -func performRequest(r http.Handler, method, path string) *httptest.ResponseRecorder { - req, _ := http.NewRequestWithContext(context.Background(), method, path, nil) +func performRequest(r http.Handler) *httptest.ResponseRecorder { + req, _ := http.NewRequestWithContext(context.Background(), "GET", "/", nil) w := httptest.NewRecorder() r.ServeHTTP(w, req) return w @@ -49,7 +49,11 @@ func createFromString() Render { func createFromStringsWithFuncs() Render { r := New() - r.AddFromStringsFuncs("index", template.FuncMap{}, `Welcome to {{ .name }} {{template "content"}}`, `{{define "content"}}template{{end}}`) + r.AddFromStringsFuncs( + "index", + template.FuncMap{}, + `Welcome to {{ .name }} {{template "content"}}`, `{{define "content"}}template{{end}}`, + ) return r } @@ -82,7 +86,7 @@ func TestAddFromFiles(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) } @@ -96,7 +100,7 @@ func TestAddFromGlob(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is login template\n", w.Body.String()) } @@ -110,7 +114,7 @@ func TestAddFromFS(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) } @@ -124,7 +128,7 @@ func TestAddFromString(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template", w.Body.String()) } @@ -138,7 +142,7 @@ func TestAddFromStringsFruncs(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template", w.Body.String()) } @@ -152,7 +156,7 @@ func TestAddFromFilesFruncs(t *testing.T) { }) }) - w := performRequest(router, "GET", "/") + w := performRequest(router) assert.Equal(t, 200, w.Code) assert.Equal(t, "Welcome to index template\n", w.Body.String()) } From a9223a4ca33d3816400f5c429b4897cf69d48fbc Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 28 Dec 2024 16:51:06 +0800 Subject: [PATCH 05/11] chore: update various Go dependencies to their latest versions - Update `github.com/bytedance/sonic` to v1.12.6 - Update `github.com/bytedance/sonic/loader` to v0.2.1 - Update `github.com/gabriel-vasile/mimetype` to v1.4.7 - Update `github.com/go-playground/validator/v10` to v10.23.0 - Update `github.com/goccy/go-json` to v0.10.4 - Update `github.com/klauspost/cpuid/v2` to v2.2.9 - Update `golang.org/x/arch` to v0.12.0 - Update `golang.org/x/crypto` to v0.31.0 - Update `golang.org/x/net` to v0.33.0 - Update `golang.org/x/sys` to v0.28.0 - Update `golang.org/x/text` to v0.21.0 - Update `google.golang.org/protobuf` to v1.36.1 Signed-off-by: appleboy --- go.mod | 24 ++++++++++++------------ go.sum | 49 ++++++++++++++++++++++++------------------------- 2 files changed, 36 insertions(+), 37 deletions(-) diff --git a/go.mod b/go.mod index 474526b..b416cd8 100644 --- a/go.mod +++ b/go.mod @@ -8,19 +8,19 @@ require ( ) require ( - github.com/bytedance/sonic v1.12.3 // indirect - github.com/bytedance/sonic/loader v0.2.0 // indirect + github.com/bytedance/sonic v1.12.6 // indirect + github.com/bytedance/sonic/loader v0.2.1 // indirect github.com/cloudwego/base64x v0.1.4 // indirect github.com/cloudwego/iasm v0.2.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect - github.com/gabriel-vasile/mimetype v1.4.5 // indirect + github.com/gabriel-vasile/mimetype v1.4.7 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-playground/validator/v10 v10.22.1 // indirect - github.com/goccy/go-json v0.10.3 // indirect + github.com/go-playground/validator/v10 v10.23.0 // indirect + github.com/goccy/go-json v0.10.4 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/klauspost/cpuid/v2 v2.2.8 // indirect + github.com/klauspost/cpuid/v2 v2.2.9 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -29,11 +29,11 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect - golang.org/x/arch v0.10.0 // indirect - golang.org/x/crypto v0.27.0 // indirect - golang.org/x/net v0.29.0 // indirect - golang.org/x/sys v0.25.0 // indirect - golang.org/x/text v0.18.0 // indirect - google.golang.org/protobuf v1.34.2 // indirect + golang.org/x/arch v0.12.0 // indirect + golang.org/x/crypto v0.31.0 // indirect + golang.org/x/net v0.33.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect + google.golang.org/protobuf v1.36.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index c9e9375..0ab4782 100644 --- a/go.sum +++ b/go.sum @@ -1,8 +1,8 @@ -github.com/bytedance/sonic v1.12.3 h1:W2MGa7RCU1QTeYRTPE3+88mVC0yXmsRQRChiyVocVjU= -github.com/bytedance/sonic v1.12.3/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= +github.com/bytedance/sonic v1.12.6 h1:/isNmCUF2x3Sh8RAp/4mh4ZGkcFAX/hLrzrK3AvpRzk= +github.com/bytedance/sonic v1.12.6/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= -github.com/bytedance/sonic/loader v0.2.0 h1:zNprn+lsIP06C/IqCHs3gPQIvnvpKbbxyXQP1iU4kWM= -github.com/bytedance/sonic/loader v0.2.0/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= +github.com/bytedance/sonic/loader v0.2.1 h1:1GgorWTqf12TA8mma4DDSbaQigE2wOgQo7iCjjJv3+E= +github.com/bytedance/sonic/loader v0.2.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/cloudwego/base64x v0.1.4 h1:jwCgWpFanWmN8xoIUHa2rtzmkd5J2plF/dnLS6Xd/0Y= github.com/cloudwego/base64x v0.1.4/go.mod h1:0zlkT4Wn5C6NdauXdJRhSKRlJvmclQ1hhJgA0rcu/8w= github.com/cloudwego/iasm v0.2.0 h1:1KNIy1I1H9hNNFEEH3DVnI4UujN+1zjpuk6gwHLTssg= @@ -10,8 +10,8 @@ github.com/cloudwego/iasm v0.2.0/go.mod h1:8rXZaNYT2n95jn+zTI1sDr+IgcD2GVs0nlbbQ 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/gabriel-vasile/mimetype v1.4.5 h1:J7wGKdGu33ocBOhGy0z653k/lFKLFDPJMG8Gql0kxn4= -github.com/gabriel-vasile/mimetype v1.4.5/go.mod h1:ibHel+/kbxn9x2407k1izTA1S81ku1z/DlgOW2QE0M4= +github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA= +github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU= 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.10.0 h1:nTuyha1TYqgedzytsKYqna+DfLos46nTv2ygFy86HFU= @@ -22,18 +22,18 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.22.1 h1:40JcKH+bBNGFczGuoBYgX4I6m/i27HYW8P9FDk5PbgA= -github.com/go-playground/validator/v10 v10.22.1/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= -github.com/goccy/go-json v0.10.3 h1:KZ5WoDbxAIgm2HNbYckL0se1fHD6rz5j4ywS6ebzDqA= -github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= +github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o= +github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/goccy/go-json v0.10.4 h1:JSwxQzIqKfmFX1swYPpUThQZp/Ka4wzJdK0LWVytLPM= +github.com/goccy/go-json v0.10.4/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PULtXL6M= 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/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.8 h1:+StwCXwm9PdpiEkPyzBXIy+M9KUb4ODm0Zarf1kS5BM= -github.com/klauspost/cpuid/v2 v2.2.8/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= +github.com/klauspost/cpuid/v2 v2.2.9 h1:66ze0taIn2H33fBvCkXuv9BmCwDfafmiIVpKV9kKGuY= +github.com/klauspost/cpuid/v2 v2.2.9/go.mod h1:rqkxqrZ1EhYM9G+hXH7YdowN5R5RGN6NK4QwQ3WMXF8= github.com/knz/go-libedit v1.10.1/go.mod h1:MZTVkCWyz0oBc7JOWP3wNAzd002ZbM/5hgShxwh4x8M= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= @@ -62,22 +62,21 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08= github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE= github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg= -golang.org/x/arch v0.10.0 h1:S3huipmSclq3PJMNe76NGwkBR504WFkQ5dhzWzP8ZW8= -golang.org/x/arch v0.10.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= -golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= -golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= -golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= -golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= -golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/arch v0.12.0 h1:UsYJhbzPYGsT0HbEdmYcqtCv8UNGvnaL561NnIUvaKg= +golang.org/x/arch v0.12.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= +golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= +golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= -golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= -golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= -golang.org/x/text v0.18.0/go.mod h1:BuEKDfySbSR4drPmRPG/7iBdf8hvFMuRexcpahXilzY= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= 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.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= -google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= +google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= +google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= From d9566cce791a70728a4c30e8285a5a7606ca13b0 Mon Sep 17 00:00:00 2001 From: Yami Odymel Date: Sat, 28 Dec 2024 16:52:45 +0800 Subject: [PATCH 06/11] feat: added AddFromFSFuncs (#64) * Fixed #62, Added AddFromFSFuncs * Added missing .Funcs(funcMap) * Fixed xxx is an incomplete or empty template --- dynamic.go | 13 +++++++++++++ multitemplate.go | 8 ++++++++ renderer.go | 1 + 3 files changed, 22 insertions(+) diff --git a/dynamic.go b/dynamic.go index a272c70..f00816f 100644 --- a/dynamic.go +++ b/dynamic.go @@ -41,6 +41,7 @@ const ( filesTemplateType globTemplateType fsTemplateType + fsFuncTemplateType stringTemplateType stringFuncTemplateType filesFuncTemplateType @@ -69,6 +70,8 @@ func (tb templateBuilder) buildTemplate() *template.Template { return template.Must(template.ParseGlob(tb.glob)) case fsTemplateType: return template.Must(template.ParseFS(tb.fsys, tb.files...)) + case fsFuncTemplateType: + return template.Must(template.New(tb.templateName).Funcs(tb.funcMap).ParseFS(tb.fsys, tb.files...)) case stringTemplateType: return template.Must(template.New(tb.templateName).Parse(tb.templateString)) case stringFuncTemplateType: @@ -113,6 +116,7 @@ func (r DynamicRender) AddFromGlob(name, glob string) *template.Template { return builder.buildTemplate() } +// AddFromFS supply add template from fs.FS (e.g. embed.FS) func (r DynamicRender) AddFromFS(name string, fsys fs.FS, files ...string) *template.Template { builder := &templateBuilder{templateName: name, fsys: fsys, files: files} builder.buildType = fsTemplateType @@ -120,6 +124,15 @@ func (r DynamicRender) AddFromFS(name string, fsys fs.FS, files ...string) *temp return builder.buildTemplate() } +// AddFromFSFuncs supply add template from fs.FS (e.g. embed.FS) with callback func +func (r DynamicRender) AddFromFSFuncs(name string, funcMap template.FuncMap, fsys fs.FS, files ...string) *template.Template { + tname := filepath.Base(files[0]) + builder := &templateBuilder{templateName: tname, funcMap: funcMap, fsys: fsys, files: files} + builder.buildType = fsFuncTemplateType + r[name] = builder + return builder.buildTemplate() +} + // AddFromString supply add template from strings func (r DynamicRender) AddFromString(name, templateString string) *template.Template { builder := &templateBuilder{templateName: name, templateString: templateString} diff --git a/multitemplate.go b/multitemplate.go index 94937b6..2f2dca2 100644 --- a/multitemplate.go +++ b/multitemplate.go @@ -57,6 +57,14 @@ func (r Render) AddFromFS(name string, fsys fs.FS, files ...string) *template.Te return tmpl } +// AddFromFSFuncs supply add template from fs.FS (e.g. embed.FS) with callback func +func (r Render) AddFromFSFuncs(name string, funcMap template.FuncMap, fsys fs.FS, files ...string) *template.Template { + tname := filepath.Base(files[0]) + tmpl := template.Must(template.New(tname).Funcs(funcMap).ParseFS(fsys, files...)) + r.Add(name, tmpl) + return tmpl +} + // AddFromString supply add template from strings func (r Render) AddFromString(name, templateString string) *template.Template { tmpl := template.Must(template.New(name).Parse(templateString)) diff --git a/renderer.go b/renderer.go index 2e48737..c0a1ea1 100644 --- a/renderer.go +++ b/renderer.go @@ -17,6 +17,7 @@ type Renderer interface { AddFromFiles(name string, files ...string) *template.Template AddFromGlob(name, glob string) *template.Template AddFromFS(name string, fsys fs.FS, files ...string) *template.Template + AddFromFSFuncs(name string, funcMap template.FuncMap, fsys fs.FS, files ...string) *template.Template AddFromString(name, templateString string) *template.Template AddFromStringsFuncs(name string, funcMap template.FuncMap, templateStrings ...string) *template.Template AddFromFilesFuncs(name string, funcMap template.FuncMap, files ...string) *template.Template From 92dd85825bc5e781249c11529543e20fa94e638c Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 28 Dec 2024 16:54:56 +0800 Subject: [PATCH 07/11] refactor: refactor and improve documentation for dynamic.go methods - Remove `exportloopref` linter from `.golangci.yml` - Improve documentation for `AddFromFSFuncs` method in `dynamic.go` - Refactor `templateBuilder` initialization for better readability in `dynamic.go` Signed-off-by: appleboy --- .golangci.yml | 1 - dynamic.go | 26 +++++++++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index d59c99b..67edf0a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -7,7 +7,6 @@ linters: - dogsled - dupl - errcheck - - exportloopref - exhaustive - gochecknoinits - goconst diff --git a/dynamic.go b/dynamic.go index f00816f..2e8577c 100644 --- a/dynamic.go +++ b/dynamic.go @@ -124,10 +124,30 @@ func (r DynamicRender) AddFromFS(name string, fsys fs.FS, files ...string) *temp return builder.buildTemplate() } -// AddFromFSFuncs supply add template from fs.FS (e.g. embed.FS) with callback func -func (r DynamicRender) AddFromFSFuncs(name string, funcMap template.FuncMap, fsys fs.FS, files ...string) *template.Template { +// AddFromFSFuncs adds a new template to the DynamicRender from the provided file system (fs.FS) and files. +// It allows you to specify a custom function map (funcMap) to be used within the template. +// +// Parameters: +// - name: The name to associate with the template in the DynamicRender. +// - funcMap: A map of functions to be used within the template. +// - fsys: The file system (fs.FS) from which to read the template files. +// - files: A variadic list of file paths to be included in the template. +// +// Returns: +// - *template.Template: The constructed template. +func (r DynamicRender) AddFromFSFuncs( + name string, + funcMap template.FuncMap, + fsys fs.FS, + files ...string, +) *template.Template { tname := filepath.Base(files[0]) - builder := &templateBuilder{templateName: tname, funcMap: funcMap, fsys: fsys, files: files} + builder := &templateBuilder{ + templateName: tname, + funcMap: funcMap, + fsys: fsys, + files: files, + } builder.buildType = fsFuncTemplateType r[name] = builder return builder.buildTemplate() From c70d2546c2008d53e0702b8f30cdf5da5d54f9ca Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 28 Dec 2024 16:58:01 +0800 Subject: [PATCH 08/11] feat: enhance dynamic template rendering with new initialization function - Add `createFromFSFuncsDynamic` function to initialize a renderer with templates from the filesystem - Add `TestAddFromFSFuncsDynamic` test to verify dynamic template rendering with Gin framework Signed-off-by: appleboy --- dynamic_test.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/dynamic_test.go b/dynamic_test.go index ef001ca..7f030fb 100644 --- a/dynamic_test.go +++ b/dynamic_test.go @@ -196,3 +196,24 @@ func TestAddingTemplate(t *testing.T) { createFromTemplatesDynamic() }) } + +func createFromFSFuncsDynamic() Renderer { + r := NewRenderer() + r.AddFromFSFuncs("index", template.FuncMap{}, os.DirFS("."), "tests/base.html", "tests/article.html") + + return r +} + +func TestAddFromFSFuncsDynamic(t *testing.T) { + router := gin.New() + router.HTMLRender = createFromFSFuncsDynamic() + router.GET("/", func(c *gin.Context) { + c.HTML(200, "index", gin.H{ + "title": "Test Multiple Template", + }) + }) + + w := performRequest(router) + assert.Equal(t, 200, w.Code) + assert.Equal(t, "

Test Multiple Template

\nHi, this is article template\n", w.Body.String()) +} From 35ef9185159b6cf9863076cb0de2d023fd0c6a31 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sat, 28 Dec 2024 16:59:54 +0800 Subject: [PATCH 09/11] docs: enhance documentation and update testing configurations - Improve the documentation for the `AddFromFS` function, providing detailed descriptions for parameters and return values. Signed-off-by: appleboy --- dynamic.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dynamic.go b/dynamic.go index 2e8577c..99546dc 100644 --- a/dynamic.go +++ b/dynamic.go @@ -116,7 +116,16 @@ func (r DynamicRender) AddFromGlob(name, glob string) *template.Template { return builder.buildTemplate() } -// AddFromFS supply add template from fs.FS (e.g. embed.FS) +// AddFromFS adds a new template to the DynamicRender from the provided file system (fs.FS) and files. +// It allows you to specify a custom function map (funcMap) to be used within the template. +// The name parameter is used to associate the template with a key in the DynamicRender. +// The files parameter is a variadic list of file paths to be included in the template. +// - name: The name to associate with the template in the DynamicRender. +// - fsys: The file system (fs.FS) from which to read the template files. +// - files: A variadic list of file paths to be included in the template. +// +// Returns: +// - *template.Template: The constructed template. func (r DynamicRender) AddFromFS(name string, fsys fs.FS, files ...string) *template.Template { builder := &templateBuilder{templateName: name, fsys: fsys, files: files} builder.buildType = fsTemplateType From 485feaae6d51974d85fa80db0eacb94484bc0168 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 28 Dec 2024 17:24:48 +0800 Subject: [PATCH 10/11] ci: expand OS support in GitHub Actions workflow for Go (#67) * ci: expand OS support in GitHub Actions workflow for Go - Add macOS and Windows to the OS matrix in the GitHub Actions workflow for Go - Specify Go build cache locations for Windows and macOS Signed-off-by: appleboy * ci: improve CI workflow and API integration - Remove Windows build job from GitHub Actions workflow Signed-off-by: appleboy --------- Signed-off-by: appleboy --- .github/workflows/go.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index caaf0aa..2954af5 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -29,11 +29,13 @@ jobs: test: strategy: matrix: - os: [ubuntu-latest] + os: [ubuntu-latest, macos-latest] go: [1.21, 1.22, 1.23] include: - os: ubuntu-latest go-build: ~/.cache/go-build + - os: macos-latest + go-build: ~/Library/Caches/go-build name: ${{ matrix.os }} @ Go ${{ matrix.go }} runs-on: ${{ matrix.os }} env: From 7b561eb19388c4ef79826e7135d52130eeeba706 Mon Sep 17 00:00:00 2001 From: appleboy Date: Sun, 29 Dec 2024 09:38:35 +0800 Subject: [PATCH 11/11] ci: add GitHub Actions workflow for Bearer PR checks - Add a GitHub Actions workflow for Bearer PR checks - Configure the workflow to trigger on pull request events [opened, synchronize, reopened] - Set permissions for contents to read and pull-requests to write - Define a job named `rule_check` that runs on `ubuntu-latest` - Include steps to checkout the repository, set up reviewdog, run Bearer report, and execute reviewdog with the generated report Signed-off-by: appleboy --- .github/workflows/bearer.yml | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/bearer.yml diff --git a/.github/workflows/bearer.yml b/.github/workflows/bearer.yml new file mode 100644 index 0000000..8dd39ab --- /dev/null +++ b/.github/workflows/bearer.yml @@ -0,0 +1,35 @@ +name: Bearer PR Check + +on: + pull_request: + types: [opened, synchronize, reopened] + +permissions: + contents: read + pull-requests: write + +jobs: + rule_check: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - uses: reviewdog/action-setup@v1 + with: + reviewdog_version: latest + + - name: Run Report + id: report + uses: bearer/bearer-action@v2 + with: + format: rdjson + output: rd.json + diff: true + + - name: Run reviewdog + if: always() + env: + REVIEWDOG_GITHUB_API_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + cat rd.json | reviewdog -f=rdjson -reporter=github-pr-review