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

1 year ago
1 year ago
1 year ago
1 year ago
  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "net"
  6. "git.chrishayward.xyz/x/users/proto"
  7. "git.chrishayward.xyz/x/users/server"
  8. "github.com/google/uuid"
  9. "google.golang.org/grpc"
  10. )
  11. var (
  12. secretDefault = uuid.NewString()
  13. secret = flag.String("secret", secretDefault, "--secret=SECRET")
  14. port = flag.Uint("port", 8080, "--port=8080")
  15. )
  16. func main() {
  17. // Parse the optional flags.
  18. flag.Parse()
  19. // If the secret has not been set print it to the console.
  20. if *secret == secretDefault {
  21. fmt.Printf("SECRET=%s\n", secretDefault)
  22. }
  23. // Create the network listener.
  24. lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
  25. if err != nil {
  26. fmt.Printf("Failed to listen: %v", err)
  27. }
  28. // Start listening for requests.
  29. srv := grpc.NewServer()
  30. proto.RegisterUsersServer(srv, server.NewUsersServer(secret))
  31. fmt.Printf("Listening on :%d", *port)
  32. srv.Serve(lis)
  33. }