From 87eae20329f1f4fed4e09f19dca36cdcfd37b489 Mon Sep 17 00:00:00 2001
From: Pawan Rawal <pawan0201@gmail.com>
Date: Wed, 20 Apr 2016 08:33:06 +0530
Subject: [PATCH] Adding documentation and refactoring to make sure lines don't
 exceed 80 chars.

---
 query/query.go |  2 ++
 server/main.go | 11 +++++++++--
 2 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/query/query.go b/query/query.go
index 13f8dfd0..e61a4e11 100644
--- a/query/query.go
+++ b/query/query.go
@@ -289,6 +289,8 @@ func extract(r *task.Result) (*pb.Result, error) {
 	return result, nil
 }
 
+// This method performs a pre traversal on a subgraph and converts it to a
+// protocol buffer Graph Response.
 func (g *SubGraph) PreTraverse() (gr *pb.GraphResponse, rerr error) {
 	gr = &pb.GraphResponse{}
 	if len(g.query) == 0 {
diff --git a/server/main.go b/server/main.go
index 33c62744..6c7e9329 100644
--- a/server/main.go
+++ b/server/main.go
@@ -50,7 +50,8 @@ var postingDir = flag.String("postings", "", "Directory to store posting lists")
 var uidDir = flag.String("uids", "", "XID UID posting lists directory")
 var mutationDir = flag.String("mutations", "", "Directory to store mutations")
 var port = flag.String("port", "8080", "Port to run server on.")
-var clientPort = flag.String("clientPort", "9090", "Port used to communicate with client on tcp")
+var clientPort = flag.String("clientPort", "9090",
+	"Port used to communicate with client.")
 var numcpu = flag.Int("numCpu", runtime.NumCPU(),
 	"Number of cores to be used by the process")
 var instanceIdx = flag.Uint64("instanceIdx", 0,
@@ -205,7 +206,11 @@ func queryHandler(w http.ResponseWriter, r *http.Request) {
 // server is used to implement pb.DGraphServer
 type server struct{}
 
-func (s *server) Query(ctx context.Context, r *pb.GraphRequest) (gr *pb.GraphResponse, rerr error) {
+// This method is used to execute the query and return the response to the
+// client as a protocol buffer message.
+func (s *server) Query(ctx context.Context,
+	r *pb.GraphRequest) (*pb.GraphResponse, error) {
+	gr := *pb.GraphResponse{}
 	if len(r.Query) == 0 {
 		glog.Error("While reading query")
 		return gr, fmt.Errorf("Empty query")
@@ -245,6 +250,8 @@ func (s *server) Query(ctx context.Context, r *pb.GraphRequest) (gr *pb.GraphRes
 	return gr, err
 }
 
+// This function register a DGraph grpc server on the address, which is used
+// exchanging protocol buffer messages.
 func runGrpcServer(address string) error {
 	ln, err := net.Listen("tcp", address)
 	if err != nil {
-- 
GitLab