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" | |
| "fmt" | |
| ) | |
| func main() { | |
| a := emailCover{Email: "12323", CreatedAt: "1213123", FullName: "321321", CreditCardInfo: "123213", Items: "21323"} | |
| str, err := json.Marshal(a) |
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" | |
| "fmt" | |
| ) | |
| func main() { | |
| a := cover{Field1: "12323", Field2: "1213123", Field3: "321321", Field4: "123213", Field5: "21323", Field6: "123123"} | |
| str, err := json.Marshal(a) |
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 ( | |
| "fmt" | |
| "math/rand" | |
| "sort" | |
| "time" | |
| ) | |
| func main() { |
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
| func main() { | |
| ctx, cancel := context.WithCancel(context.Background()) | |
| go func() { | |
| for { | |
| select { | |
| // This usage will ignore actual time | |
| // Just runs in every 5 second | |
| case <-ctx.Done(): | |
| return | |
| case <-time.Tick(time.Second * 5): |
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
| func main() { | |
| ctx, cancel := context.WithCancel(context.Background()) | |
| go func() { | |
| fmt.Println("Let's wait 5 minute") | |
| WaitUntilWithContext(ctx, time.Minute*5) | |
| fmt.Println("Hey!! Why we exited after 5 second !?!??!") | |
| }() | |
| time.Sleep(5 * time.Second) | |
| cancel() | |
| time.Sleep(10 * time.Second) |
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
| func main() { | |
| for { | |
| select { | |
| // This usage will ignore actual time | |
| // Just runs in every 5 second | |
| case <-time.Tick(time.Second * 5): | |
| fmt.Println("I'm a bot that saying 'You are amazing' in every 5 second") | |
| } | |
| } | |
| } |
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
| func main() { | |
| // This will print the time every 5 seconds | |
| for theTime := range time.Tick(time.Second * 5) { | |
| fmt.Println(theTime.Format("2006-01-02 15:04:05")) | |
| } | |
| } |
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
| func main() { | |
| // Set when we want to continue | |
| until, _ := time.Parse(time.RFC3339, "2023-01-01T00:00:01+02:00") | |
| // Wait until it | |
| <-time.After(time.Until(until)) | |
| } |
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
| func main() { | |
| // This will block for 5 seconds and then return the current time | |
| theTime := <-time.After(time.Second * 5) | |
| fmt.Println(theTime.Format("2006-01-02 15:04:05")) | |
| } |
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
| func main() { | |
| // This will block for 5 seconds and then return the current time | |
| theTime := <-time.After(time.Second * 5) | |
| fmt.Println(theTime.Format("2006-01-02 15:04:05")) | |
| } |