gin框架简记

Gin

简述

Go是一门正在快速增长的编程语言,专为构建简单...

三种框架Gin,Beego,Lris。

生成初始化mod文件
go mod init main.go

Gin安装使用

go get 类似 git -clone

Golang下载gin框架报错解决,Golang

https://blog.csdn.net/haohao_gege/article/details/128334591

设置GO GOPROXY代理设置

https://blog.csdn.net/m0_67393413/article/details/126100779

设置

Gin的HelloWorld

执行 go get -u github.com/gin-gonic/gin

安装Gin相关。

go.mod文件

//创建模块
module gin_demo
go 1.18

//类似Java的maven
//go env -w GOPROXY=https://goproxy.cn  设置国内代理
// 如果下面出现异常 设置  GOPROXY=https://goproxy.io

require (
	github.com/bytedance/sonic v1.8.2 // indirect
	github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect
	github.com/gin-contrib/sse v0.1.0 // indirect
	省略.......
)

main.go

//package gin_demo
package main //建立go的入口文件
//导入  gin 包
import (
	"github.com/gin-gonic/gin"
)
func main() {
	//创建一个服务
	ginServer := gin.Default()
	//访问地址,处理请求 Request Response
	ginServer.GET("/hello", func(context *gin.Context) {
		context.JSONP(200, gin.H{"massage": "hello,world"})
	})
	//服务器端口
	err := ginServer.Run(":8082")
	if err != nil {
		return 
	}
}

RESTful API

之前格式

get /user

post /creatr_user

post /update_user

post /delete_user

RESTful API

get /user

post /creatr_user

put /update_user

delete /delete_user

给前端相应页面

go会把项目打包成EXE文件

posted @ 2023-02-27 07:20  渝思  阅读(37)  评论(0编辑  收藏  举报