package main import ( "context" ) type LastNameList struct { KeyList [][]byte } func (ln *LastNameList) GetKeyList() [][]byte { return ln.KeyList } func (ln *LastNameList) AppendKey(key []byte) { ln.KeyList = append(ln.KeyList, key) } func (ln *LastNameList) GetLength() int { return len(ln.KeyList) } type FirstNameList struct { KeyList [][]byte } func (fn *FirstNameList) GetKeyList() [][]byte { return fn.KeyList } func (fn *FirstNameList) AppendKey(key []byte) { fn.KeyList = append(fn.KeyList, key) } func (fn *FirstNameList) GetLength() int { return len(fn.KeyList) } type nameserver struct { } func (s *nameserver) FirstName(cxt context.Context, request *NameRequest) (*NameReply, error) { reply := &NameReply{} reply.Message = string(GetRandomKey(fnl)) // switch request.GetNametype() { // case NameType_FullName: // var fullname []byte // fullname = append(fullname, GetRandomKey(fnl)...) // fullname = append(fullname, GetRandomKey(lnl)...) // reply.Message = string(fullname) // case NameType_FirstName: // reply.Message = string(GetRandomKey(fnl)) // case NameType_LastName: // reply.Message = string(GetRandomKey(lnl)) // } return reply, nil } func (s *nameserver) LastName(cxt context.Context, request *NameRequest) (*NameReply, error) { reply := &NameReply{} reply.Message = string(GetRandomKey(lnl)) return reply, nil } func (s *nameserver) FullName(cxt context.Context, request *NameRequest) (*NameReply, error) { reply := &NameReply{} var fullname []byte fullname = append(fullname, GetRandomKey(fnl)...) fullname = append(fullname, GetRandomKey(lnl)...) reply.Message = string(fullname) return reply, nil }