This repository has been archived by the owner on Dec 8, 2022. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 148
/
address.go
66 lines (55 loc) · 1.47 KB
/
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
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
package faker
import (
"reflect"
"github.com/bxcodec/faker/v4/pkg/options"
)
// GetAddress returns a new Addresser interface of Address
func GetAddress() Addresser {
address := &Address{}
return address
}
// Addresser is logical layer for Address
type Addresser interface {
Latitude(v reflect.Value) (interface{}, error)
Longitude(v reflect.Value) (interface{}, error)
}
// Address struct
type Address struct{}
func (i Address) latitude() float32 {
return (rand.Float32() * 180) - 90
}
// Latitude sets latitude of the address
func (i Address) Latitude(v reflect.Value) (interface{}, error) {
kind := v.Kind()
val := i.latitude()
if kind == reflect.Float32 {
return val, nil
}
return float64(val), nil
}
func (i Address) longitude() float32 {
return (rand.Float32() * 360) - 180
}
// Longitude sets longitude of the address
func (i Address) Longitude(v reflect.Value) (interface{}, error) {
kind := v.Kind()
val := i.longitude()
if kind == reflect.Float32 {
return val, nil
}
return float64(val), nil
}
// Longitude get fake longitude randomly
func Longitude(opts ...options.OptionFunc) float64 {
return singleFakeData(LONGITUDE, func() interface{} {
address := Address{}
return float64(address.longitude())
}, opts...).(float64)
}
// Latitude get fake latitude randomly
func Latitude(opts ...options.OptionFunc) float64 {
return singleFakeData(LATITUDE, func() interface{} {
address := Address{}
return float64(address.latitude())
}, opts...).(float64)
}