Beispiel #1
0
func NewStation(userid string) (*pb.Station, error) {
	var s pb.Station

	s.Userid = proto.String(userid)

	id, err := CryptoRandId()
	if err != nil {
		return nil, err
	}
	s.Id = proto.String(id)

	secret := make([]byte, 20)
	_, err = io.ReadFull(crand.Reader, secret)
	if err != nil {
		return nil, err
	}
	s.Secret = proto.String(base64.StdEncoding.EncodeToString(secret))

	now := time.Now().Unix()
	s.Created = &now

	s.Name = proto.String("Unnamed Station")

	return &s, nil
}