From 74e5b29b4ffc42a61814f802d1d74bffe3e5db68 Mon Sep 17 00:00:00 2001 From: Christopher James Hayward Date: Sat, 1 Jul 2023 13:41:33 -0400 Subject: [PATCH] Cleanup --- cmd/server/main.go | 9 +++++---- {cmd/server => server}/server.go | 4 ++-- {cmd/server => server}/token_db.go | 2 +- {cmd/server => server}/user_db.go | 4 ++-- 4 files changed, 10 insertions(+), 9 deletions(-) rename {cmd/server => server}/server.go (98%) rename {cmd/server => server}/token_db.go (98%) rename {cmd/server => server}/user_db.go (97%) diff --git a/cmd/server/main.go b/cmd/server/main.go index 43b3026..1308101 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,10 +3,10 @@ package main import ( "flag" "fmt" - "log" "net" "git.chrishayward.xyz/x/users/proto" + "git.chrishayward.xyz/x/users/server" "github.com/google/uuid" "google.golang.org/grpc" ) @@ -23,17 +23,18 @@ func main() { // If the secret has not been set print it to the console. if *secret == secretDefault { - fmt.Printf("SECRET=%s", secretDefault) + fmt.Printf("SECRET=%s\n", secretDefault) } // Create the network listener. lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) if err != nil { - log.Fatalf("Failed to listen: %v", err) + fmt.Printf("Failed to listen: %v", err) } // Start listening for requests. srv := grpc.NewServer() - proto.RegisterUsersServer(srv, newUsersServer(secret)) + proto.RegisterUsersServer(srv, server.NewUsersServer(secret)) + fmt.Printf("Listening on :%d", *port) srv.Serve(lis) } diff --git a/cmd/server/server.go b/server/server.go similarity index 98% rename from cmd/server/server.go rename to server/server.go index e082c57..6f6d623 100644 --- a/cmd/server/server.go +++ b/server/server.go @@ -1,4 +1,4 @@ -package main +package server import ( "context" @@ -20,7 +20,7 @@ type usersServer struct { resetTokens TokenDB } -func newUsersServer(secret *string) proto.UsersServer { +func NewUsersServer(secret *string) proto.UsersServer { return &usersServer{ secret: secret, users: newInMemoryUserDB(), diff --git a/cmd/server/token_db.go b/server/token_db.go similarity index 98% rename from cmd/server/token_db.go rename to server/token_db.go index 70227d2..d16acb8 100644 --- a/cmd/server/token_db.go +++ b/server/token_db.go @@ -1,4 +1,4 @@ -package main +package server import ( "errors" diff --git a/cmd/server/user_db.go b/server/user_db.go similarity index 97% rename from cmd/server/user_db.go rename to server/user_db.go index ba95507..3fa86ef 100644 --- a/cmd/server/user_db.go +++ b/server/user_db.go @@ -1,4 +1,4 @@ -package main +package server import "errors" @@ -16,7 +16,7 @@ type UserDB interface { type inMemoryUserDB struct { UserDB - nextID int + nextID int64 users []*User }