Use log instead of fmt for logging
Also fix up a few errors to lower case
This commit is contained in:
parent
1cafd4f2ce
commit
2f5863b17a
10 changed files with 49 additions and 47 deletions
|
@ -42,7 +42,7 @@ func (a *Accountant) RegisterAccount(name string) (acc Account, err error) {
|
|||
// Verify this acount isn't already registered
|
||||
for _, a := range a.Accounts {
|
||||
if a.Name == acc.Name {
|
||||
return Account{}, fmt.Errorf("Account name already registered")
|
||||
return Account{}, fmt.Errorf("account name already registered")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -31,15 +31,15 @@ func (a *accountantServer) Register(ctx context.Context, in *accounts.RegisterIn
|
|||
defer a.sync.Unlock()
|
||||
|
||||
// Try and register the account itself
|
||||
fmt.Printf("Registering account: %s\n", in.Name)
|
||||
log.Printf("Registering account: %s\n", in.Name)
|
||||
if _, err := a.accountant.RegisterAccount(in.Name); err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
log.Printf("Error: %s\n", err)
|
||||
return &accounts.RegisterResponse{Success: false, Error: fmt.Sprintf("error registering account: %s", err)}, nil
|
||||
}
|
||||
|
||||
// Save out the accounts
|
||||
if err := persistence.Save("accounts", a.accountant); err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
log.Printf("Error: %s\n", err)
|
||||
return &accounts.RegisterResponse{Success: false, Error: fmt.Sprintf("failed to save accounts: %s", err)}, nil
|
||||
}
|
||||
|
||||
|
@ -52,10 +52,10 @@ func (a *accountantServer) AssignValue(_ context.Context, in *accounts.DataKeyVa
|
|||
defer a.sync.RUnlock()
|
||||
|
||||
// Try and assign the data
|
||||
fmt.Printf("Assigning value for account %s: %s->%s\n", in.Account, in.Key, in.Value)
|
||||
log.Printf("Assigning value for account %s: %s->%s\n", in.Account, in.Key, in.Value)
|
||||
err := a.accountant.AssignData(in.Account, in.Key, in.Value)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
log.Printf("Error: %s\n", err)
|
||||
return &accounts.Response{Success: false, Error: err.Error()}, nil
|
||||
}
|
||||
|
||||
|
@ -69,10 +69,10 @@ func (a *accountantServer) GetValue(_ context.Context, in *accounts.DataKey) (*a
|
|||
defer a.sync.RUnlock()
|
||||
|
||||
// Try and fetch the rover
|
||||
fmt.Printf("Getting value for account %s: %s\n", in.Account, in.Key)
|
||||
log.Printf("Getting value for account %s: %s\n", in.Account, in.Key)
|
||||
data, err := a.accountant.GetValue(in.Account, in.Key)
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %s\n", err)
|
||||
log.Printf("Error: %s\n", err)
|
||||
return &accounts.DataResponse{Success: false, Error: err.Error()}, nil
|
||||
}
|
||||
|
||||
|
@ -110,12 +110,12 @@ func main() {
|
|||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
go func() {
|
||||
<-c
|
||||
fmt.Println("Quit requested, exiting...")
|
||||
log.Println("Quit requested, exiting...")
|
||||
grpcServer.Stop()
|
||||
}()
|
||||
|
||||
// Serve the RPC server
|
||||
fmt.Printf("Serving accountant on %s\n", address)
|
||||
log.Printf("Serving accountant on %s\n", address)
|
||||
if err := grpcServer.Serve(lis); err != nil {
|
||||
log.Fatalf("failed to server gRPC: %s", err)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue