You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.3 KiB
48 lines
1.3 KiB
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net/http"
|
|
|
|
"git.chrishayward.xyz/x/users/gateway"
|
|
"git.chrishayward.xyz/x/users/proto"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
var (
|
|
port = flag.Int("port", 8081, "--port=8081")
|
|
serverAddr = flag.String("serverAddr", "localhost", "--serverAddr=localhost")
|
|
serverPort = flag.Int("serverPort", 8080, "--serverPort=8080")
|
|
serverSecret = flag.String("serverSecret", "...", "--serverSecret=...")
|
|
)
|
|
|
|
func main() {
|
|
// Parse the optional flags.
|
|
flag.Parse()
|
|
|
|
// Create the connection to the server.
|
|
conn, err := grpc.Dial(fmt.Sprintf("%s:%d", *serverAddr, *serverPort))
|
|
if err != nil {
|
|
fmt.Printf("Failed to connect: %v", err)
|
|
}
|
|
|
|
// Defer closing the connection.
|
|
defer conn.Close()
|
|
|
|
// Create the client.
|
|
client := proto.NewUsersClient(conn)
|
|
|
|
// Setup HTTP endpoints.
|
|
http.HandleFunc("/register", gateway.Register(client))
|
|
http.HandleFunc("/login", gateway.Login(client))
|
|
http.HandleFunc("/authorize", gateway.Authorize(client, serverSecret))
|
|
http.HandleFunc("/reset_password", gateway.ResetPassword(client))
|
|
http.HandleFunc("/change_password", gateway.ChangePassword(client))
|
|
|
|
// Listen for requests.
|
|
fmt.Printf("Forwarding from :%d to %s:%d", *port, *serverAddr, *serverPort)
|
|
if err := http.ListenAndServe(fmt.Sprintf(":%d", *port), nil); err != nil {
|
|
fmt.Printf("Failed to listen: %v", err)
|
|
}
|
|
}
|