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 (
"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)
}

4
cmd/server/server.go → 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(),

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

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

4
cmd/server/user_db.go → 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
}
Loading…
Cancel
Save