Compare commits
No commits in common. "369fda6adb9546449543245d7204d883784e5e91" and "5accc42e13012dc5059e994af40842fe746ac131" have entirely different histories.
369fda6adb
...
5accc42e13
@ -1 +0,0 @@
|
||||
* { color: red; }
|
@ -1 +0,0 @@
|
||||
console.log("hello, world!")
|
@ -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)
|
||||
}
|
||||
}
|
@ -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>
|
8
main.go
8
main.go
@ -38,9 +38,7 @@ package main
|
||||
// import "git.sangeeth.dev/gobyexample/linefilter"
|
||||
// import "git.sangeeth.dev/gobyexample/exit"
|
||||
// import "git.sangeeth.dev/gobyexample/filepath"
|
||||
// import "git.sangeeth.dev/gobyexample/dir"
|
||||
// import "git.sangeeth.dev/gobyexample/tmp"
|
||||
import "git.sangeeth.dev/gobyexample/embed"
|
||||
import "git.sangeeth.dev/gobyexample/dir"
|
||||
|
||||
func main() {
|
||||
// runes.Runes()
|
||||
@ -81,7 +79,5 @@ func main() {
|
||||
// linefilter.LineFilter()
|
||||
// exit.Exit()
|
||||
// filepath.Filepath()
|
||||
// dir.Dir()
|
||||
// tmp.Tmp()
|
||||
embed.Embed()
|
||||
dir.Dir()
|
||||
}
|
||||
|
37
tmp/tmp.go
37
tmp/tmp.go
@ -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")
|
||||
}
|
Loading…
Reference in New Issue
Block a user