-
Notifications
You must be signed in to change notification settings - Fork 0
/
address.go
34 lines (28 loc) · 904 Bytes
/
address.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
package SexModel
import (
"github.com/Plankiton/SexPistol/Cartridge"
"encoding/json"
"net/http"
"fmt"
)
type Address struct {
SexDB.Model
Street string `json:"street,omitempty"`
State string `json:"state,omitempty"`
Number string `json:"number,omitempty"`
Code string `json:"cep,omitempty"`
City string `json:"city,omitempty"`
Neigh string `json:"neighborhood,omitempty"`
Compl string `json:"complement,omitempty" gorm:"default:NULL"`
}
func (model *Address) FromPostalCode(cep string) *Address {
model.Code = cep
r_addr, err := http.Get(fmt.Sprintf("https://brasilapi.com.br/api/cep/v1/%s", model.Code))
if err == nil && r_addr.StatusCode == 200 {
json.NewDecoder(r_addr.Body).Decode(&model)
}
return model
}
func (m Address) TableName() string {
return "addresses"
}