-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrating with Gin #4
Comments
Hi @dstroot. You are definitely on the right track though. |
rg := restgate.New("X-Auth-Key", "X-Auth-Secret", restgate.Static, restgate.Config{Context: C, Key: []string{"12345"}, Secret: []string{"secret"}}))
rgAdapter := func(c *gin.Context) {
nextAdapter := func(http.ResponseWriter, *http.Request) {
c.Next()
}
rg.ServeHTTP(c.Writer, c.Request, nextAdapter)
}
r.Use(rgAdapter) |
Awesome! This compiles and runs (I am getting output from Restgate). Now I am looking to see if there is a development config setting that will not require HTTPS in development. Thoughts? {"code":"3","error":"Please use HTTPS connection"}{"taxProApi":"/v1/:year/taxpro/:efin"} This code works! // Initialize Restgate
rg := restgate.New("X-Auth-Key", "X-Auth-Secret", restgate.Static, restgate.Config{Key: []string{"12345"}, Secret: []string{"secret"}})
// Create Gin middleware - integrate Restgate with Gin
rgAdapter := func(c *gin.Context) {
nextAdapter := func(http.ResponseWriter, *http.Request) {
c.Next()
}
rg.ServeHTTP(c.Writer, c.Request, nextAdapter)
}
// Use Restgate with Gin
r.Use(rgAdapter) |
Sorry - I found it. rg := restgate.New("X-Auth-Key", "X-Auth-Secret", restgate.Static, restgate.Config{
Key: []string{"12345"},
Secret: []string{"secret"},
HTTPSProtectionOff: true,
}) |
When restgate fails to validate, it should not write any more to the ResponseWriter. Something is not right there: You will have to call rgAdapter := func(c *gin.Context) {
nextCalled := false
nextAdapter := func(http.ResponseWriter, *http.Request) {
nextCalled = true
c.Next()
}
rg.ServeHTTP(c.Writer, c.Request, nextAdapter)
if nextCalled == false {
c.AbortWithStatus(401)
}
} |
r = gin.Default()
// Initialize Restgate
rg := restgate.New("X-Auth-Key", "X-Auth-Secret", restgate.Static, restgate.Config{Key: []string{"12345"}, Secret: []string{"secret"}})
// Create Gin middleware - integrate Restgate with Gin
rgAdapter := func(c *gin.Context) {
nextCalled := false
nextAdapter := func(http.ResponseWriter, *http.Request) {
nextCalled = true
c.Next()
}
rg.ServeHTTP(c.Writer, c.Request, nextAdapter)
if nextCalled == false {
c.AbortWithStatus(401)
}
}
// Use Restgate with Gin
r.Use(rgAdapter) |
I want to redirect to some 401 page rather than the code:
in the gin. What should I do like this ? |
I tried :
But the error msg is the same as before:
|
The issue is the package was designed for making APIs. Redirects are unusual for a API response. |
Alternatively, Then:
You can use the |
Ok, thank you very much ! @pjebs |
Anyone tried integrating this with Gin? Would something like this work?
The text was updated successfully, but these errors were encountered: