gin路由

This commit is contained in:
2025-11-18 22:43:31 +08:00
parent 295c2900a6
commit c314f705d0
2 changed files with 55 additions and 25 deletions

36
go.mod
View File

@@ -1,3 +1,39 @@
module awesomeProject module awesomeProject
go 1.25 go 1.25
require (
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.14.2 // indirect
github.com/bytedance/sonic/loader v0.4.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/gabriel-vasile/mimetype v1.4.11 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/gin-gonic/gin v1.11.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.28.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // 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.4 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.56.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
go.uber.org/mock v0.6.0 // indirect
golang.org/x/arch v0.23.0 // indirect
golang.org/x/crypto v0.44.0 // indirect
golang.org/x/mod v0.30.0 // indirect
golang.org/x/net v0.47.0 // indirect
golang.org/x/sync v0.18.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/text v0.31.0 // indirect
golang.org/x/tools v0.39.0 // indirect
google.golang.org/protobuf v1.36.10 // indirect
)

44
main.go
View File

@@ -1,30 +1,24 @@
package main package main
import "fmt" import "github.com/gin-gonic/gin"
func main() { func main() {
var p Person r := gin.Default()
p.Name = "John Doe" //从服务器请求资源
p.test() r.GET("/", func(c *gin.Context) {
fmt.Println(p.Name) c.String(200, "这是一个get请求用于取出资源")
p.test1() })
fmt.Println(p.Name) r.POST("/add", func(c *gin.Context) {
} c.String(200, "这是一个post--主要用于增加数据")
})
// Person 定义结构体 r.PUT("/edit", func(c *gin.Context) {
type Person struct { c.String(200, "这是一个put请求 主要用于编辑数据")
Name string })
} r.DELETE("/delete", func(c *gin.Context) {
c.String(200, "这是一个delete请求 主要用于删除数据")
// 给Person结构体绑定方法test })
func (s Person) test() { err := r.Run()
fmt.Println(s.Name) if err != nil {
s.Name = "sssbbb" return
} // listen and serve on 0.0.0.0:8080
}
// 给Person结构体绑定方法test,指针传递
func (s *Person) test1() {
fmt.Println(s.Name)
s.Name = "佳佳"
} }