Created
March 23, 2021 17:45
-
-
Save APratham/c22f37e141d1794aeeb46d931f42b045 to your computer and use it in GitHub Desktop.
AutoUpdate
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" | |
"io" | |
"io/ioutil" | |
"log" | |
"math/rand" | |
"os" | |
"strings" | |
"time" | |
) | |
func makeReadme(filename string) error { | |
// Read entire file content, giving us little control but | |
// making it very simple. No need to close the file. | |
content, err := ioutil.ReadFile("facts.txt") | |
if err != nil { | |
log.Fatal(err) | |
} | |
// Convert []byte to string and print to screen | |
// text := string(content) | |
// fmt.Println(text) | |
rand.Seed(time.Now().UnixNano()) | |
str := string(content) | |
fact := rand.Intn(len(content)) | |
lines := strings.Split(string(str), "\n") | |
date := time.Now().Format("2 Jan 2006") | |
hello := "### Hello! I’m Antariksh Pratham." | |
quote := "⚡ Fun fact: " + lines[fact] | |
updated := "<sub>Last updated by magic on " + date + ".</sub>" | |
data := fmt.Sprintf("%s\n\n%s\n\n%s\n", hello, quote, updated) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Error screenshot