Created
          August 26, 2023 16:12 
        
      - 
      
- 
        Save maguec/7a18090f9a390c2be47aad7d382ac960 to your computer and use it in GitHub Desktop. 
    GoFakeIt to JSON file example
  
        
  
    
      This file contains hidden or 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 ( | |
| "encoding/json" | |
| "os" | |
| "github.com/brianvoe/gofakeit/v6" | |
| ) | |
| type Record struct { | |
| Uuid string `fake:"{uuid}" json:"uuid"` | |
| UserId string `fake:"{username}" json:"username"` | |
| FirstName string `fake:"{firstname}" json:"firstname"` | |
| LastName string `fake:"{lastname}" json:"lastname"` | |
| Company string `fake:"{company}" json:"company"` | |
| Title string `fake:"{jobtitle}" json:"title"` | |
| Email string `fake:"{email}" json:"email"` | |
| Cell string `fake:"{phoneformatted}" json:"cellphone"` | |
| Years int `fake:"{number:1,10}" json:"tenure"` | |
| } | |
| func main() { | |
| var r Record | |
| f, err := os.Create("data.json") | |
| if err != nil { | |
| panic(err) | |
| } | |
| for i := 1; i <= 1000000; i++ { | |
| gofakeit.Struct(&r) | |
| data, _ := json.Marshal(r) | |
| _, err := f.WriteString(string(data) + "\n") | |
| if err != nil { | |
| panic(err) | |
| } | |
| } | |
| err = f.Close() | |
| if err != nil { | |
| panic(err) | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment