This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
"strconv" | |
"strings" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
"github.com/gin-gonic/gin" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.Use(func(c *gin.Context) { | |
// Forward the request to the target server | |
proxy.ServeHTTP(c.Writer, c.Request) | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"log" | |
"net/http" | |
"net/http/httputil" | |
"net/url" | |
"github.com/gin-gonic/gin" | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
target, _ := url.Parse("http://localhost:8081/base/") | |
// Create a reverse proxy | |
proxy := &httputil.ReverseProxy{ | |
Rewrite: func(r *httputil.ProxyRequest) { | |
log.Println("Forwarding:", r.In.URL.String()) | |
r.SetURL(target) | |
r.Out.Host = r.In.Host | |
}, | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"net/http" | |
"github.com/gin-gonic/gin" | |
) | |
func launchSecondServer() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"fmt" | |
"io" | |
"log" | |
"net/http" | |
"golang.org/x/oauth2" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mux.HandleFunc("GET /consume", func(w http.ResponseWriter, r *http.Request) { | |
ctx := context.Background() | |
code := r.FormValue("code") | |
state := r.FormValue("state") | |
if state != "state" { | |
http.Error(w, "Error, mismatched state", http.StatusBadRequest) | |
return | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
func main() { | |
mux := http.NewServeMux() | |
conf := &oauth2.Config{ | |
ClientID: "RANDOM", | |
ClientSecret: "RANDOM", | |
Scopes: []string{"offline_access"}, | |
Endpoint: oauth2.Endpoint{ | |
TokenURL: "https://oauth.wiremockapi.cloud/oauth/token", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
... | |
func main() { | |
mux := http.NewServeMux() | |
// Map a route to handle requests to the root path ("/") | |
mux.HandleFunc("GET /login", func(w http.ResponseWriter, r *http.Request) { |
NewerOlder