by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Seyidna Ali
@seyidnaali
I user Graphql on gin-go
func New() {

    router := gin.Default()

    router.Use(CORSMiddleware())
    // router.Use(MyCustomMiddleWare())
    router.Use(gin.Logger())
    router.Use(gin.Recovery())

    router.GET("/graphql", graphql.Handler())
    router.POST("/graphql", graphql.Handler())
    router.Run(":5000")

}
Phillip Couto
@phillipCouto
@seyidnaali that is a frontend question and not related to gin. I am sure a quick search on stackoverflow will give you answers on how to securely store a token in the browser.
Masmoudi
@TnPoDoLsKi
Hi everyone i m implimenting Jwt based authentication in my web application with gin , im so confused i didin't find popular authentication middleware or library
Nayan Jyoti Das
@NayanJD
Hi! I am just new to Go and Gin framework. I just wanted to know how to detect foreign key conflict during insertion. I am using Gorm and Postgres. I want to catch the conflict error and return conflict status code along with an appropriate message.
Nayan Jyoti Das
@NayanJD
Hey! Found a way for that. Seems like for postgres the errors are of type *pq.Error. It contains Message and Code. I am currently checking the Code to detect foreign key violation. If anybody has better suggestion, please let me know.
Evershift
@Evershift1_twitter
Hi everyone! I am trying to understand the best way to create and manage migrations for a postrges database with Gin
I happen to be using GORM, but it looks like their migration support is very limited...
linuxMengfan
@linuxMengfan
How is close response headers "Transfer-Encoding: chunked "? because frontend error. I want try close it.
Kris Carr
@kriscarr_gitlab
Is it possible for gin to automatically pick the correct response renderer based on the "Accept" header? I cannot seem to find a relevant function in the gin.Context, just explicit ones like .JSON(), .XML() etc
tfreedy
@tfreedy
Hi everyone! is there a session that uses mysql for backend?
Leonardo Velasquez
@levelasquez

Hello,

I'm trying to test a handler that received a param from url, but i can't set the param key/value to the test request :(

Does anyone know how to do it?

Thanks.

Zakaria Amine
@zak905
hello everybody
I am trying to register a custom validator based on the example here: https://github.com/gin-gonic/examples/blob/master/custom-validation/server.go
    v, ok := binding.Validator.Engine().(*validator.Validate)
    if ok {
        v.RegisterStructValidation(validateUserAcceptedTerms, User{})
    }
however I always get ok is false
did things change since the example was updated ? I am using the v1.6.2 version
Zakaria Amine
@zak905
I am using github.com/go-playground/validator/v9 version v9.31.0
Zakaria Amine
@zak905
it started working when I switched to github.com/go-playground/validator/v10, I saw that the library was using v10 internally, so this was probably the reason
Jose Diaz-Gonzalez
@josegonzalez
Does anyone know if there is a way to change the attached routes based on an incoming header?
Basically what I'd like to do is respond with https://github.com/manyminds/api2go resources if the request has an Accept: application/json header, respond with a particular handler on all routes if the User-Agent starts with the text git/, and use my normal html-based gin routes otherwise
Govind07
@Govind07
Hey
Phillip Couto
@phillipCouto
@josegonzalez I would create a middleware that accepts gin.HandlerFunc arguments and inside based on your condition passes the context to the next appropriate function
Otherwise I would look at the godoc to see if there is a method on the Context to do what you are asking
Bo-Yi Wu
@appleboy
Performance issue: gin-gonic/gin#2350
in v1.6.2
Bo-Yi Wu
@appleboy
Gin release v1.6.3
Seyidna Ali
@seyidnaali
hello evryOne
Tiago Brito
@tlfbrito_twitter
Hi everyone, is there a way to disable "Transfer-Encoding: chunked" and use Content-length instead ?
TARIK SARI
@intrepid-tr
hi everyone
    i := 0
    for i < 100 {
        i++
    }
    fmt.Println(i) =   output =100

    i := 0
    for i < =100 {
        i++
    }
    fmt.Println(i) = output= 101
what is the diffrence i < 100 | i <= 100
Seyidna Ali
@seyidnaali
hello how can user aggregate uisng golang ?
db.Reservations.aggregate([ {
    $project: {
        _id: 1,
        idrecord: "$idrecord",
        idborrower: "$idborrower",
        dateres: "$dateres",
    }
}, {
    $sort: {
        idborrower : -1
    }
}, {
    $group: {
        _id: {},
        list: {
            $push: {
                idrecord: '$idrecord',
                idborrower: '$idborrower',
                dateres: '$dateres',
            }
        }
    }
}, {
    $unwind: {
        path: '$list',
        includeArrayIndex: 'Rank',
    }
}, {
    $sort: {
        'list.dateres': 1,
        'list.idborrower': -1
    }
}, {
    $group: {
        _id: '$list.idborrower',
        list: {
            $push: {
                idrecord: '$list.idrecord',
                idborrower: '$list.idborrower',
                dateres: '$list.dateres',
                Rank: '$Rank'
            }
        }
    }
}, {
    $unwind: {
        path: '$list',
        includeArrayIndex: 'BorrowerRank',
    }
}, {
    $project: {
        _id: 0,
        idrecord: '$list.idrecord',
        idborrower: '$list.idborrower',
        dateres: '$list.dateres',
        Rank: '$list.Rank',

    }
}])
how use this in go ?
letmutx
@letmutx
does binding:"required" tag work on structs while validating body? i can't seem to get it to work. the following always returns StatusOK for the {"payload": "something"}
type Graph struct {
    GraphId string `json:"graph"`
}

type pushPayload struct {
    Payload interface{} `json:"payload" binding:"required"`
    Graph   Graph       `json:"graph" binding:"required"`
}

func main() {
    router := gin.Default()
    router.POST("/api/v1/push", func(c *gin.Context) {
        var payload pushPayload
        if err := c.ShouldBindJSON(&payload); err != nil {
            c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
            return
        }
        c.JSON(http.StatusOK, gin.H{"status": "worked"})
    })
    router.Run(":8080")
}
letmutx
@letmutx
had to use a *Graph to make it work
Anthony Anonde
@tonymj76

Please this issue has been eating me up

//Router returns the api resources
func Router() *gin.Engine {
    service := new(Service)
    router := gin.Default()
    merchantAPI := router.Group("/api/v1/merchants")
    {
        merchantAPI.POST("/", service.CreateMerchant)
        merchantAPI.GET("/", service.ListMerchants)
        merchantAPI.PATCH("/", service.UpdateMerchant)
        merchantAPI.GET("/:merchant_id", service.GetMerchantByID)
        merchantAPI.DELETE("/:merchant_id", service.DeleteMerchantByID)
        //outlets routes
        merchantAPI.POST("/outlets/", service.CreateMerchantOutlet)
        merchantAPI.GET("/outlets/:merchant_id", service.GetMerchantOutlets)
        merchantAPI.PATCH("/outlets/", service.UpdateMerchantOutlet)
        merchantAPI.DELETE("/outlets/", service.DeleteMerchantOutlet)
    }

    return router
}

i do get this error

[GIN-debug] GET    /api/v1/merchants/outlets/:merchant_id --> github.com/Investliftng/ocm-api/merchant/api/handler.(*Service).GetMerchantOutlets-fm (3 handlers)
panic: 'outlets' in new path '/api/v1/merchants/outlets/:merchant_id' conflicts with existing wildcard ':merchant_id' in existing prefix '/api/v1/merchants/:merchant_id'
even if i try changing :merchant_id to :m_id i still get the same error. I also remove the :merchant_id from outlets i still get the same error msg... Do gin cache my routes?
Anthony Anonde
@tonymj76
i fix this by creating a new group for outlet eg outletapi := router.Group("/api/v1/outlets")
docker-laravel
@rainbowMorelhahahah
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
_ = v.RegisterValidation("phone", Validators.PhoneDate);
}
if v, ok := binding.Validator.Engine().(*validator.Validate); ok {
_ = v.RegisterValidation("phone", Validators.PhoneDate);
} Undefined validation function
Undefined validation function
pickupdwq
@pickupdwq
Anyone could tell me a pointer concept in GOlang?
Seyidna Ali
@seyidnaali
hello
we have 2 functions that returns 2 different types struct GraphQL how can I manage to return the good result with the right type?
var getResultat =&graphql.Field{
    Type : ????????????
    Args : graphql.FieldConfigArgument{
        "type": &graphql.ArgumentConfig{
            Type : strings,
        }
        "code": &graphql.ArgumentConfig{
            Type : strings,
        }
    }
    Resolve: func(p graphql.ResolveParams) (interface{}, error) {
        filter := bson.M{}
        if T := p.Args["type"]; T != nil {
            filter["type"] = T.(string)
            return (&models.A{}).listA(filter)
        }
        if B := p.Args["isHappy"]; B != nil {

            filter["isbn"] = I.(string)
        }
         return (&models.Book{}).listB(filter)

    },
}
how to check the type regarding the result (Atype or Booktype)
OuyangDanwen
@OuyangDanwen
Hi, I am wondering if it is possible to add new routes dynamically after running gin.Engine by doing r.Run(). The use case is that I want to periodically update the routes based on some remote config without redeploying the application.