Repository: googleforgames/open-saves
Pull request #257 (2021-05-13 19:06:26)

refactor: rename New{Store,Record}FromProto to FromProto


<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://github.com/googleforgames/open-saves/blob/main/docs/contributing.md and developer guide https://github.com/googleforgames/open-saves/blob/main/docs/development.md
2. Please label this pull request according to what type of issue you are addressing.
3. Ensure you have added or ran the appropriate tests for your PR.
-->

**What type of PR is this?**
/kind refactor

**What this PR does / Why we need it**:
Renames New{Store,Record}FromProto to FromProto for consistency and conciseness as they are in separate packages now.

**Which issue(s) this PR fixes**:
<!--
*Automatically closes linked issue when PR is merged.
Usage: `Closes #<issue number>`, or `Closes (paste link of issue)`.
-->
Closes #

**Special notes for your reviewer**:



Patch:
diff --git a/internal/app/server/open_saves.go b/internal/app/server/open_saves.go
index 864958f..a783e5e 100644
--- a/internal/app/server/open_saves.go
+++ b/internal/app/server/open_saves.go
@@ -101,7 +101,7 @@ func (s *openSavesServer) CreateStore(ctx context.Context, req *pb.CreateStoreRe
 }
 
 func (s *openSavesServer) CreateRecord(ctx context.Context, req *pb.CreateRecordRequest) (*pb.Record, error) {
-	record := record.NewRecordFromProto(req.Record)
+	record := record.FromProto(req.Record)
 	if err := checkRecord(record); err != nil {
 		return nil, err
 	}
@@ -199,7 +199,7 @@ func (s *openSavesServer) GetRecord(ctx context.Context, req *pb.GetRecordReques
 }
 
 func (s *openSavesServer) UpdateRecord(ctx context.Context, req *pb.UpdateRecordRequest) (*pb.Record, error) {
-	updateTo := record.NewRecordFromProto(req.GetRecord())
+	updateTo := record.FromProto(req.GetRecord())
 	if err := checkRecord(updateTo); err != nil {
 		return nil, err
 	}
diff --git a/internal/pkg/metadb/record/record.go b/internal/pkg/metadb/record/record.go
index 4ed0c19..565f13b 100644
--- a/internal/pkg/metadb/record/record.go
+++ b/internal/pkg/metadb/record/record.go
@@ -99,9 +99,9 @@ func (r *Record) ToProto() *pb.Record {
 	return ret
 }
 
-// NewRecordFromProto creates a new Record instance from a proto.
+// FromProto creates a new Record instance from a proto.
 // Passing nil returns a zero-initialized proto.
-func NewRecordFromProto(p *pb.Record) *Record {
+func FromProto(p *pb.Record) *Record {
 	if p == nil {
 		return new(Record)
 	}
diff --git a/internal/pkg/metadb/store/store.go b/internal/pkg/metadb/store/store.go
index 45f0374..75ec683 100644
--- a/internal/pkg/metadb/store/store.go
+++ b/internal/pkg/metadb/store/store.go
@@ -73,9 +73,9 @@ func (s *Store) LoadKey(k *datastore.Key) error {
 	return nil
 }
 
-// NewStoreFromProto creates a new Store instance from a proto.
+// FromProto creates a new Store instance from a proto.
 // Passing nil returns a zero-initialized Store.
-func NewStoreFromProto(p *pb.Store) *Store {
+func FromProto(p *pb.Store) *Store {
 	if p == nil {
 		return new(Store)
 	}


Test patch:
diff --git a/internal/pkg/metadb/record/record_test.go b/internal/pkg/metadb/record/record_test.go
index 82d4e13..d34610e 100644
--- a/internal/pkg/metadb/record/record_test.go
+++ b/internal/pkg/metadb/record/record_test.go
@@ -299,13 +299,13 @@ func TestRecord_NewRecordFromProto(t *testing.T) {
 			UpdatedAt: updatedAt,
 		},
 	}
-	actual := NewRecordFromProto(proto)
+	actual := FromProto(proto)
 	assert.Equal(t, expected, actual)
 }
 
 func TestRecord_NewRecordFromProtoNil(t *testing.T) {
 	expected := new(Record)
-	actual := NewRecordFromProto(nil)
+	actual := FromProto(nil)
 	assert.NotNil(t, actual)
 	assert.Equal(t, expected, actual)
 }
diff --git a/internal/pkg/metadb/store/store_test.go b/internal/pkg/metadb/store/store_test.go
index 229632a..0839191 100644
--- a/internal/pkg/metadb/store/store_test.go
+++ b/internal/pkg/metadb/store/store_test.go
@@ -27,7 +27,7 @@ import (
 )
 
 func TestStore_NewStoreFromProtoNil(t *testing.T) {
-	actual := NewStoreFromProto(nil)
+	actual := FromProto(nil)
 	assert.NotNil(t, actual)
 	assert.Equal(t, new(Store), actual)
 }
@@ -78,7 +78,7 @@ func TestStore_NewStoreFromProtoSimple(t *testing.T) {
 			UpdatedAt: updatedAt,
 		},
 	}
-	actual := NewStoreFromProto(proto)
+	actual := FromProto(proto)
 	assert.Equal(t, expected, actual)
 }