jjzjj

mongodb - 使用 gin-golang 将数据从 mongodb 显示到 html 页面?

我正在尝试检查MongoDB是否包含具有特定用户名和密码的数据。但是现在我得到的是所有数据而不是指定的数据。下面是我的代码:r.POST("/login",func(c*gin.Context){logedUser:=[]RegisterdUser{}name:=c.PostForm("userName")Password:=c.PostForm("userPassword")fmt.Println("insidecheckingsectionnnn",name,Password)session,err:=mgo.Dial("localhost:27017")iferr!=nil{pa

go - 在golang中使用gin包为特定路由表达中间件?

我为成功运行的路由制作了一个中间件,但有一个小问题,它会应用于所有路由,包括signup和login。我想社交signup和login路线,所有用户都将访问这两条路线。以下是我正在使用的代码:-路线.go/*SignupRoute*/Route{"SaveUser","POST","/signup",controller.SaveUser},/*LoginRoute*/Route{"LoginUser","POST","/login",controller.Login},/*AllCustomersRoutes*/Route{"SaveCustomers","POST","/custo

windows - 在 Windows 上安装 swaggo (swagger + gin)

我正在尝试在Windows上为gin-gonic设置swagger。swaggo的文档指出我应该运行:goget-ugithub.com/swaggo/swag/cmd/swag安装后我应该能够从我的项目的根目录中运行swaginit我有main.go,但是cmdlet声明如下:swag:Theterm'swag'isnotrecognizedasthenameofacmdlet,function,scriptfile,oroperableprogram.Checkthespellingofthename,orifapathwasincluded,verifythatthepathis

使用 GIn-Gonic 进行用户登录

我在制作Web应用程序时使用gin-gonic登录时遇到了一些麻烦。我目前正在为此使用API。我可以在那里提出进入请求。这是我的代码片段:主要//LOGINrouter.GET("/login",loginUser)router.POST("/login",login)登录功能的代码段//LOGINFUNCTIONSfuncloginUser(c*gin.Context){c.HTML(200,"login.html",gin.H{})}funclogin(c*gin.Context){email:=c.PostForm("email")password:=c.PostForm("pa

go - 使用 gin 包从 Postman Form 获取数据后没有显示任何值

下面是我正在处理的代码。它在运行时显示一条成功消息,但不显示postman表单中定义的值。相反,它在命令提示符中显示空格。packagemainimport("fmt""github.com/gin-gonic/gin")funcsaveCustomer(c*gin.Context){fn:=c.PostForm("firstName")ln:=c.PostForm("lastName")em:=c.PostForm("email")phnno:=c.PostForm("phone_no")fmt.Printf("fn:%v;ln:%v;em:%v;phnno:%v;",fn,ln,e

go - Gin-Gonic 限制路由

我的webapp有滥用的手段,用户可以访问他们不应该访问的东西,例如127.0.0.1/users/1&127.0.0.1/users/2&127.0.0.1/users/3等等,其中显示了用户的注册电子邮件、ip等(通过JSON,因此Web服务器可以返回自定义消息、问候语,并允许用户在配置文件设置中编辑帐户数据)这是我的路线:forum.GET("/users/:user_id",routeFunc(UsersGET))我正在使用Gin-GonicHTTP框架创建一个虚拟论坛,有人可以告诉我如何阻止用户访问/users/路由,同时允许实际的网络服务器自由使用吗?也许将我链接到正确的方

go - 如何从 *http.Request 和 *httptest.ResponseRecorder 创建 gin.Context?

我想为gin创建一个测试助手类似于testify'sHTTPBodyContain.我很难从*http.Request和*httptest.ResponseRecorder创建gin.Context。我已经写过这样的东西:funcHTTPBodyContains(t*testing.T,handlergin.HandlerFunc,method,urlstring,valuesurl.Values,strinterface{},msgAndArgs...interface{})bool{body:=HTTPBody(handler,method,url,values)contains:

go - Fullcalendar 不呈现从 golang gin 获取的事件

我是golang和web-dev的新手,我使用gin作为api为fullcalendar提供事件作为json。这是我的全日历事件配置:$(function(){$('#calendar').fullCalendar({header:{left:'prev,nexttoday',center:'title',right:'month,agendaWeek,agendaDay'},defaultView:'month',events:{url:'/events',type:'POST'}})});下面是我的Gin处理程序:funcEventsJSON(c*gin.Context){star

go - 如何在 Gin 的上下文中获取匹配的路由?

我有这段代码:packagemainimport("net/http""github.com/gin-gonic/gin")funcmain(){r:=gin.New()r.GET("/user/:id",func(c*gin.Context){//HowcanIgetthelitteralstring"/user/:id"here?c.JSON(http.StatusOK,gin.H{"message":"receivedrequest"})})}有什么方法可以在处理程序中检索乱码字符串/user/:id?如果我使用c.Request.Path,它将给我路径的完整输出,如/user/

golang gin 加载 html 超时

Gin加载index.html时总是报错r:=gin.New()r.Use(gin.Logger())r.Use(gin.Recovery())r.LoadHTMLGlob("views/**/*")r.GET("/",func(g*gin.Context){g.HTML(http.StatusOK,"index/index.html",gin.H{"title":"test",})2018/11/2720:23:46[Recovery]2018/11/27-20:23:46panicrecovered:GET/HTTP/1.1Host:localhost:8080Accept:tex