data_workshop/country.go

37 lines
679 B
Go
Raw Normal View History

2020-05-19 10:12:18 +00:00
package main
import (
context "context"
"encoding/gob"
)
// Country struct
type Country struct {
Pic []byte
Name []byte
}
var countrylist *KeyList = &KeyList{}
func init() {
gob.Register(Country{})
LoadGob("./data/country.gob", countrylist)
}
type countryserver struct {
}
func (s *countryserver) Name(cxt context.Context, request *Request) (*Reply, error) {
reply := &Reply{}
reply.Message = string(GetRandomKey(countrylist).(Country).Name)
return reply, nil
}
func (s *countryserver) Picture(cxt context.Context, request *Request) (*CountryReply, error) {
reply := &CountryReply{}
reply.Image = GetRandomKey(countrylist).(Country).Pic
return reply, nil
}