Browse Source

Cleanup

master
parent
commit
74e5b29b4f
Signed by: chris GPG Key ID: 3025DCBD46F81C0F
  1. 9
      cmd/server/main.go
  2. 4
      server/server.go
  3. 2
      server/token_db.go
  4. 4
      server/user_db.go

9
cmd/server/main.go

@ -3,10 +3,10 @@ package main
import ( import (
"flag" "flag"
"fmt" "fmt"
"log"
"net" "net"
"git.chrishayward.xyz/x/users/proto" "git.chrishayward.xyz/x/users/proto"
"git.chrishayward.xyz/x/users/server"
"github.com/google/uuid" "github.com/google/uuid"
"google.golang.org/grpc" "google.golang.org/grpc"
) )
@ -23,17 +23,18 @@ func main() {
// If the secret has not been set print it to the console. // If the secret has not been set print it to the console.
if *secret == secretDefault { if *secret == secretDefault {
fmt.Printf("SECRET=%s", secretDefault)
fmt.Printf("SECRET=%s\n", secretDefault)
} }
// Create the network listener. // Create the network listener.
lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port)) lis, err := net.Listen("tcp", fmt.Sprintf(":%d", *port))
if err != nil { if err != nil {
log.Fatalf("Failed to listen: %v", err)
fmt.Printf("Failed to listen: %v", err)
} }
// Start listening for requests. // Start listening for requests.
srv := grpc.NewServer() srv := grpc.NewServer()
proto.RegisterUsersServer(srv, newUsersServer(secret))
proto.RegisterUsersServer(srv, server.NewUsersServer(secret))
fmt.Printf("Listening on :%d", *port)
srv.Serve(lis) srv.Serve(lis)
} }

4
cmd/server/server.go → server/server.go

@ -1,4 +1,4 @@
package main
package server
import ( import (
"context" "context"
@ -20,7 +20,7 @@ type usersServer struct {
resetTokens TokenDB resetTokens TokenDB
} }
func newUsersServer(secret *string) proto.UsersServer {
func NewUsersServer(secret *string) proto.UsersServer {
return &usersServer{ return &usersServer{
secret: secret, secret: secret,
users: newInMemoryUserDB(), users: newInMemoryUserDB(),

2
cmd/server/token_db.go → server/token_db.go

@ -1,4 +1,4 @@
package main
package server
import ( import (
"errors" "errors"

4
cmd/server/user_db.go → server/user_db.go

@ -1,4 +1,4 @@
package main
package server
import "errors" import "errors"
@ -16,7 +16,7 @@ type UserDB interface {
type inMemoryUserDB struct { type inMemoryUserDB struct {
UserDB UserDB
nextID int
nextID int64
users []*User users []*User
} }
Loading…
Cancel
Save