Skip to content

Commit

Permalink
Merge 261d8f6 into dbdff0b
Browse files Browse the repository at this point in the history
  • Loading branch information
brotherlogic committed Dec 31, 2018
2 parents dbdff0b + 261d8f6 commit a88a82c
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 60 deletions.
132 changes: 74 additions & 58 deletions proto/wantslist.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions proto/wantslist.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ syntax = "proto3";

package wantslist;

message Config {
repeated WantList lists = 1;
}

message WantListEntry {
int32 want = 1;
int32 index = 2;
Expand All @@ -13,7 +17,9 @@ message WantList {
}


message AddWantListRequest {}
message AddWantListRequest {
WantList add = 1;
}

message AddWantListResponse {}

Expand All @@ -23,5 +29,5 @@ message GetWantListResponse {}

service WantService {
rpc AddWantList(AddWantListRequest) returns (AddWantListResponse) {};
rpc GetWantList(GetWantListRequest) returns (GetWantListResponse) {};
//rpc GetWantList(GetWantListRequest) returns (GetWantListResponse) {};
}
29 changes: 29 additions & 0 deletions wantslist.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ import (
"google.golang.org/grpc"

pbg "github.com/brotherlogic/goserver/proto"
pb "github.com/brotherlogic/wantslist/proto"
)

const (
// KEY - where the wantslists are stored
KEY = "/github.com/brotherlogic/wantslist/config"
)

//Server main server type
type Server struct {
*goserver.GoServer
config *pb.Config
}

// Init builds the server
func Init() *Server {
s := &Server{
&goserver.GoServer{},
&pb.Config{},
}
return s
}
Expand All @@ -36,8 +44,29 @@ func (s *Server) ReportHealth() bool {
return true
}

func (s *Server) save(ctx context.Context) {
s.KSclient.Save(ctx, KEY, s.config)
}

func (s *Server) load(ctx context.Context) error {
config := &pb.Config{}
data, _, err := s.KSclient.Read(ctx, KEY, config)

if err != nil {
return err
}

s.config = data.(*pb.Config)
return nil
}

// Mote promotes/demotes this server
func (s *Server) Mote(ctx context.Context, master bool) error {
if master {
err := s.load(ctx)
return err
}

return nil
}

Expand Down

0 comments on commit a88a82c

Please sign in to comment.