Compare commits

..

No commits in common. "369fda6adb9546449543245d7204d883784e5e91" and "5accc42e13012dc5059e994af40842fe746ac131" have entirely different histories.

6 changed files with 2 additions and 93 deletions

View File

@ -1 +0,0 @@
* { color: red; }

View File

@ -1 +0,0 @@
console.log("hello, world!")

View File

@ -1,37 +0,0 @@
package embed
import (
"embed"
"fmt"
"os"
"path/filepath"
"text/template"
)
//go:embed home.html
var HomeTemplateString string
//go:embed assets/index.css
//go:embed assets/index.js
var folder embed.FS
func Embed() {
cssBytes, err := folder.ReadFile(filepath.Join("assets", "index.css"))
check(err)
jsBytes, err := folder.ReadFile(filepath.Join("assets", "index.js"))
check(err)
fmt.Println("index.css:")
fmt.Println(string(cssBytes))
fmt.Println("index.js:")
fmt.Println(string(jsBytes))
fmt.Println("Parsing template and printing it:")
t := template.Must(template.New("home").Parse(HomeTemplateString))
t.Execute(os.Stdout, string("John"))
}
func check(err error) {
if err != nil {
panic(err)
}
}

View File

@ -1,11 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{ . }}</title>
</head>
<body>
<h1>{{ . }}</h1>
</body>
</html>

View File

@ -38,9 +38,7 @@ package main
// import "git.sangeeth.dev/gobyexample/linefilter" // import "git.sangeeth.dev/gobyexample/linefilter"
// import "git.sangeeth.dev/gobyexample/exit" // import "git.sangeeth.dev/gobyexample/exit"
// import "git.sangeeth.dev/gobyexample/filepath" // import "git.sangeeth.dev/gobyexample/filepath"
// import "git.sangeeth.dev/gobyexample/dir" import "git.sangeeth.dev/gobyexample/dir"
// import "git.sangeeth.dev/gobyexample/tmp"
import "git.sangeeth.dev/gobyexample/embed"
func main() { func main() {
// runes.Runes() // runes.Runes()
@ -81,7 +79,5 @@ func main() {
// linefilter.LineFilter() // linefilter.LineFilter()
// exit.Exit() // exit.Exit()
// filepath.Filepath() // filepath.Filepath()
// dir.Dir() dir.Dir()
// tmp.Tmp()
embed.Embed()
} }

View File

@ -1,37 +0,0 @@
package tmp
import (
"fmt"
"os"
"path/filepath"
"strconv"
)
func check(err error) {
if err != nil {
panic(err)
}
}
func Tmp() {
f, err := os.CreateTemp("", "gobyexample")
check(err)
fmt.Println("Created tmp file", f.Name())
defer os.Remove(f.Name())
n1, err := f.WriteString("test")
check(err)
fmt.Println("Wrote", n1, "bytes")
dirPath, err := os.MkdirTemp("", "gobyexample")
check(err)
fmt.Println("Created temp dir at", dirPath)
defer os.RemoveAll(dirPath)
err = os.WriteFile(filepath.Join(dirPath, "file1"), []byte("tmpdir file"), 0600)
check(err)
fmt.Println("Stuff written to tmp file inside", dirPath)
b1, err := os.ReadFile(filepath.Join(dirPath, "file1"))
check(err)
fmt.Println(strconv.Quote(string(b1)), "was written to file")
}