data_workshop/country.go
huangsimin 27c0277ba8 init
2020-05-19 18:12:18 +08:00

37 lines
679 B
Go

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
}