go-gin

Custom error status code with gqlgen + go gin

流过昼夜 提交于 2021-01-29 07:40:49
问题 Recently I have been updating my GO REST APIs into graphQl API's and I came across issue where I am unable to customise my status code with gqlgen. Response I got Headers Status Code: 200 OK { data: null, errors: [ {message: "Unauthorized access", path: ["..."]} ] } Expected Header Status Code: 401 UNAUTHORISED Any help would be really appreciating! 回答1: Assume you have a gqlgen resolver similar to this: func (r *queryResolver) SecretItems(ctx context.Context, userID string, password string)

Custom error status code with gqlgen + go gin

戏子无情 提交于 2021-01-29 07:35:21
问题 Recently I have been updating my GO REST APIs into graphQl API's and I came across issue where I am unable to customise my status code with gqlgen. Response I got Headers Status Code: 200 OK { data: null, errors: [ {message: "Unauthorized access", path: ["..."]} ] } Expected Header Status Code: 401 UNAUTHORISED Any help would be really appreciating! 回答1: Assume you have a gqlgen resolver similar to this: func (r *queryResolver) SecretItems(ctx context.Context, userID string, password string)

Mapping one type to another

帅比萌擦擦* 提交于 2021-01-07 01:36:17
问题 Let's say I have the following types. type Contract struct { Id string `json:"id" gorm:"column:uuid"` Name string `json:"name" gorm:"column:name"` Description string `json:"descr" gorm:"column:descr"` ContractTypeId int `json:"contract_type_id" gorm:"column:contract_type_id"` } type ContractModel struct { Id string `json:"id" gorm:"column:uuid"` Name string `json:"name" gorm:"column:name"` Description string `json:"descr" gorm:"column:descr"` } I have a SQL query using gorm to scan results

Mapping one type to another

﹥>﹥吖頭↗ 提交于 2021-01-07 01:36:15
问题 Let's say I have the following types. type Contract struct { Id string `json:"id" gorm:"column:uuid"` Name string `json:"name" gorm:"column:name"` Description string `json:"descr" gorm:"column:descr"` ContractTypeId int `json:"contract_type_id" gorm:"column:contract_type_id"` } type ContractModel struct { Id string `json:"id" gorm:"column:uuid"` Name string `json:"name" gorm:"column:name"` Description string `json:"descr" gorm:"column:descr"` } I have a SQL query using gorm to scan results

Mapping one type to another

只谈情不闲聊 提交于 2021-01-07 01:35:19
问题 Let's say I have the following types. type Contract struct { Id string `json:"id" gorm:"column:uuid"` Name string `json:"name" gorm:"column:name"` Description string `json:"descr" gorm:"column:descr"` ContractTypeId int `json:"contract_type_id" gorm:"column:contract_type_id"` } type ContractModel struct { Id string `json:"id" gorm:"column:uuid"` Name string `json:"name" gorm:"column:name"` Description string `json:"descr" gorm:"column:descr"` } I have a SQL query using gorm to scan results

Go Gin Gonic Unit Testing Deployment Issue

倖福魔咒の 提交于 2020-12-15 05:29:45
问题 I have a Go API built using the Gin framework. Reading the docs in the testing section here, i tried to implement something similar: main.go package main import ( "mes/routes" "github.com/gin-gonic/gin" ) func setupMainRoutes(engine *gin.Engine) { engine.GET("/mesg/:language/services", routes.AllServices) engine.GET("/mesg/:language/service/:id", routes.OneService) engine.GET("/mesg/:language/services/search", routes.SearchService) } func setupErrorRoutes(engine *gin.Engine) { engine.NoRoute

Go Gin Gonic Unit Testing Deployment Issue

*爱你&永不变心* 提交于 2020-12-15 05:29:09
问题 I have a Go API built using the Gin framework. Reading the docs in the testing section here, i tried to implement something similar: main.go package main import ( "mes/routes" "github.com/gin-gonic/gin" ) func setupMainRoutes(engine *gin.Engine) { engine.GET("/mesg/:language/services", routes.AllServices) engine.GET("/mesg/:language/service/:id", routes.OneService) engine.GET("/mesg/:language/services/search", routes.SearchService) } func setupErrorRoutes(engine *gin.Engine) { engine.NoRoute

How to combine group of routes in gin?

我与影子孤独终老i 提交于 2020-12-12 12:20:14
问题 I have created two different Groups for gin routing specifically /user and /todo in two different packages and I want to merge them into one file . Here is my userroutes.go file. package userrouter import ( "github.com/gin-gonic/gin" ) //UserRoutes for user func UserRoutes() *gin.RouterGroup { r := gin.Default() v1 := r.Group("/user") { v1.GET("/hello", func(c *gin.Context) { c.JSON(200, gin.H{ "message": "pong", }) }) } return v1 } and todoroutes.go as package todorouter import ( "github.com