37 lines
679 B
Go
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
|
|
}
|