Last active
July 21, 2020 00:29
-
-
Save devmeireles/65fdb9ba92d9825bafa6d425d831e732 to your computer and use it in GitHub Desktop.
Golang random data with faker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"github.com/bxcodec/faker" | |
) | |
// DataFakerStructure is a representation of a datafaker obj | |
type DataFakerStructure struct { | |
Name string `faker:"name"` | |
Email string `faker:"email"` | |
PhoneNumber string `faker:"phone_number"` | |
UnixTime int64 `faker:"unix_time"` | |
} | |
// Student is a representation of a student obj | |
type Student struct { | |
Name string | |
Email string | |
Phone string | |
UnixTime int64 | |
} | |
func main() { | |
var student Student | |
dataFaker := DataFakerStructure{} | |
err := faker.FakeData(&dataFaker) | |
if err != nil { | |
fmt.Println(err) | |
} | |
student.Name = dataFaker.Name | |
student.Email = dataFaker.Email | |
student.Phone = dataFaker.PhoneNumber | |
student.UnixTime = dataFaker.UnixTime | |
fmt.Printf("%+v", student) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment