From c314f705d0a14974097070ebe097d0da8b72a426 Mon Sep 17 00:00:00 2001 From: nannanwu Date: Tue, 18 Nov 2025 22:43:31 +0800 Subject: [PATCH] =?UTF-8?q?gin=E8=B7=AF=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 36 ++++++++++++++++++++++++++++++++++++ main.go | 44 +++++++++++++++++++------------------------- 2 files changed, 55 insertions(+), 25 deletions(-) diff --git a/go.mod b/go.mod index 6de2d5e..bbdd5b4 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,39 @@ module awesomeProject 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 +) diff --git a/main.go b/main.go index 93c0377..96f60f2 100644 --- a/main.go +++ b/main.go @@ -1,30 +1,24 @@ package main -import "fmt" +import "github.com/gin-gonic/gin" func main() { - var p Person - p.Name = "John Doe" - p.test() - fmt.Println(p.Name) - p.test1() - fmt.Println(p.Name) -} - -// Person 定义结构体 -type Person struct { - Name string -} - -// 给Person结构体绑定方法test -func (s Person) test() { - fmt.Println(s.Name) - s.Name = "sssbbb" - -} - -// 给Person结构体绑定方法test,指针传递 -func (s *Person) test1() { - fmt.Println(s.Name) - s.Name = "佳佳" + r := gin.Default() + //从服务器请求资源 + r.GET("/", func(c *gin.Context) { + c.String(200, "这是一个get请求,用于取出资源") + }) + r.POST("/add", func(c *gin.Context) { + c.String(200, "这是一个post--主要用于增加数据") + }) + r.PUT("/edit", func(c *gin.Context) { + c.String(200, "这是一个put请求 主要用于编辑数据") + }) + r.DELETE("/delete", func(c *gin.Context) { + c.String(200, "这是一个delete请求 主要用于删除数据") + }) + err := r.Run() + if err != nil { + return + } // listen and serve on 0.0.0.0:8080 }