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.
40 lines
880 B
40 lines
880 B
package main
|
|
|
|
import (
|
|
"flag"
|
|
"fmt"
|
|
"net"
|
|
|
|
"git.chrishayward.xyz/x/users/proto"
|
|
"git.chrishayward.xyz/x/users/server"
|
|
"github.com/google/uuid"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
var (
|
|
secretDefault = uuid.NewString()
|
|
secret = flag.String("secret", secretDefault, "--secret=SECRET")
|
|
port = flag.Uint("port", 8080, "--port=8080")
|
|
)
|
|
|
|
func main() {
|
|
// Parse the optional flags.
|
|
flag.Parse()
|
|
|
|
// If the secret has not been set print it to the console.
|
|
if *secret == secretDefault {
|
|
fmt.Printf("SECRET=%s\n", secretDefault)
|
|
}
|
|
|
|
// Create the network listener.
|
|
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
|
|
if err != nil {
|
|
fmt.Printf("Failed to listen: %v", err)
|
|
}
|
|
|
|
// Start listening for requests.
|
|
srv := grpc.NewServer()
|
|
proto.RegisterUsersServer(srv, server.NewUsersServer(secret))
|
|
fmt.Printf("Listening on :%d", *port)
|
|
srv.Serve(lis)
|
|
}
|