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.

39 lines
800 B

  1. package main
  2. import (
  3. "flag"
  4. "fmt"
  5. "log"
  6. "net"
  7. "git.chrishayward.xyz/x/users/proto"
  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", secretDefault)
  22. }
  23. // Create the network listener.
  24. lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
  25. if err != nil {
  26. log.Fatalf("Failed to listen: %v", err)
  27. }
  28. // Start listening for requests.
  29. srv := grpc.NewServer()
  30. proto.RegisterUsersServer(srv, newUsersServer(secret))
  31. srv.Serve(lis)
  32. }