/gotway

Building gateway in Golang

Primary LanguageGo

⚙️ Gotway

Gateway in go

📦 Versions and dependencies

How to run

go build cmd/gotway/main.go ./main -p -p=config/server.yml

🛠️ How to configure

port: 8080
routes:
  - path: "/one"
    uri: http://localhost:8081/helloone
    headers:
      token: token-default
  - path: "/two"
    uri: http://localhost:8081/helloone

How to do a real test

The first step, to test in real environment, launch a test rest endpoint like:

package main

import (
	"fmt"
	"log"
	"net/http"

	"github.com/gorilla/mux"
)

func main() {
	r := mux.NewRouter()
	r.PathPrefix("/").HandlerFunc(PrintPathEndpoint)
	http.Handle("/", r)
	log.Fatal(http.ListenAndServe(":8081", r))
}

func PrintPathEndpoint(w http.ResponseWriter, r *http.Request) {
	fmt.Fprintf(w, "Path: %s", r.URL.Path)
}

Run the test application and configure the gotway, example:

port: 8080
routes:
  - path: "/one"
    uri: http://localhost:8081/helloone
    headers:
      token: token-default
  - path: "/two"
    uri: http://localhost:8081/helloone

Build and launch gotway and test it

Result directly test application

test application

Result with gotway

gotway

🔐 Login

curl --header "Content-Type: application/json" --data '{"user":"apascuaslco@gmail.com","password":"12345"}' -v http://localhost:8080/api/v1/signup curl --header "Content-Type: application/json" --data '{"user":"apascuaslco@gmail.com","password":"12345"}' -v http://localhost:8080/api/v1/login curl -H "Content-Type; application/json" -H "Authorization: Bearer " -v http://localhost:8080/api/v1/hello