-
Notifications
You must be signed in to change notification settings - Fork 0
/
peregrino.go
82 lines (61 loc) · 1.38 KB
/
peregrino.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package main
import (
"bufio"
"encoding/json"
"fmt"
"os"
"time"
)
type Pilgrim struct {
name string
dni string
address string
creationTime time.Time
creationPlace string
motivations string
}
func (t *Pilgrim) GetName() string {
return t.name
}
func (t *Pilgrim) GetDni() string {
return t.dni
}
func (t *Pilgrim) GetAddress() string {
return t.address
}
func (t *Pilgrim) GetCreationTime() time.Time {
return t.creationTime
}
func (t *Pilgrim) GetCreationPlace() string {
return t.creationPlace
}
func (t *Pilgrim) GetMotivations() string {
return t.motivations
}
func GetPilgrimFromJson(data []byte) (Pilgrim, error) {
var pil Pilgrim
err := json.Unmarshal(data, &pil)
if err != nil {
return pil, err
}
return pil, nil
}
// TODO Acabar el método
func GetPilgrimFromTerminal(hostelid string) (Pilgrim, error) {
var pil Pilgrim
reader := bufio.NewReader(os.Stdin)
fmt.Println("=== Formulario: Alta de Peregrinos ===")
fmt.Print("Nombre: ")
namer, _ := reader.ReadString('\n')
fmt.Print("DNI: ")
dnir, _ := reader.ReadString('\n')
fmt.Print("Dirección: ")
addressr, _ := reader.ReadString('\n')
fmt.Print("Motivaciones: ")
motivationsr, _ := reader.ReadString('\n')
pil = Pilgrim{namer, dnir, addressr, time.Now(), hostelid, motivationsr}
return pil, nil
}
func (t *Pilgrim) GetJson() ([]byte, error) {
return json.Marshal(t)
}