File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed
Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ package main
22
33import "os"
44
5- // OpenCreateFile open an existed file or create a file if not exists
5+ // OpenCreateFile opens an existing file or creates a new file if it does not exist
66func OpenCreateFile (path string ) * os.File {
77 if _ , err := os .Stat (path ); os .IsNotExist (err ) {
88 f , err := os .Create (path )
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ "io/ioutil"
6+ "log"
7+ )
8+
9+ func write () {
10+ content := []byte ("Hello, Golang!" )
11+ err := ioutil .WriteFile ("example.txt" , content , 0644 )
12+ if err != nil {
13+ log .Fatal (err )
14+ }
15+ }
16+
17+ func read () {
18+ content , err := ioutil .ReadFile ("example.txt" )
19+ if err != nil {
20+ log .Fatal (err )
21+ }
22+
23+ fmt .Printf ("File content: %s\n " , content )
24+ }
25+
26+ func main () {
27+ write ()
28+ read ()
29+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ import (
77)
88
99func main () {
10+ start := time .Now ()
11+ fmt .Println ("Current time:" , start )
12+ //Current time: 2023-04-05 19:43:23.329968 +0200 CEST m=+0.000140960
13+
1014 fmt .Println (strconv .FormatInt (time .Now ().Unix (), 10 ))
1115 //1401403874
1216 fmt .Println (time .Now ().Format (time .RFC850 ))
@@ -21,4 +25,8 @@ func main() {
2125 //1973-11-29T22:33:09+01:00
2226 fmt .Println (time .Unix (1234567890 , 0 ).Format (time .RFC822 ))
2327 //14 Feb 09 00:31 CET
28+
29+ elapsed := time .Since (start )
30+ fmt .Println ("Time elapsed:" , elapsed )
31+ //Time elapsed: 428.458µs
2432}
You can’t perform that action at this time.
0 commit comments