# wget https://golang.org/dl/go1.16.linux-amd64.tar.gz # tar -xvzf go1.16.linux-amd64.tar.gz /usr/local # go version go version go1.16 linux/amd64
import _ "embed" //go:embed hello.txt var s string print(s)
//go:embed hello.txt tmpl/* var f embed.F
package main import ( "embed" "fmt" ) // main.go 파일의 내용을 읽어서 string 변수에 저장한다. //go:embed main.go var code string // hello.txt, tmpl/* 를 FS 변수에 저장한다. //go:embed hello.txt tmpl/* var f embed.FS func main() { fmt.Println(code) data, _ := f.ReadFile("hello.txt") fmt.Println(string(data)) data, _ = f.ReadFile("tmpl/hello.tmpl") fmt.Println(string(data)) }
# cat version.txt 1.0.0-as99dhj
package main import ( _ "embed" "fmt" ) //go:embed version.txt var version string func main() { fmt.Print(version) }
. ├── card │ ├── card.html │ └── default.css ├── go.mod ├── index.html └── main.go
package main import ( "embed" "net/http" ) //go:embed *.html card/* var webUI embed.FS func main() { http.Handle("/", http.FileServer(http.FS(webUI))) http.ListenAndServe(":8888", nil) }
<!DOCTYPE html> <HTML lang="en"> <head> <!-- Compressed CSS --> <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/foundation-sites@6.6.3/dist/css/foundation.min.css" integrity="sha256-ogmFxjqiTMnZhxCqVmcqTvjfe1Y/ec4WaRj/aQPvn+I=" crossorigin="anonymous"> <link rel="stylesheet" href="/card/default.css"> <title>Card</title> </head> <body> <div class="grid-x"> <div class="cell large-12"> <ul class="pricing-table"> <li class="title">Enterprise</li> <li class="price">$99.99</li> <li class="description">An awesome description</li> <li>42 Rad Features</li> <li>7GB of Power</li> <li><a class="button" href="#">Buy Now</a></li> </ul> </div> </div> <script> $(document).foundation(); </script> </body> </HTML>
.pricing-table { background-color: #fefefe; border: solid 1px #cacaca; text-align: center; list-style-type: none; } .pricing-table li { border-bottom: dotted 1px #cacaca; padding: 0.875rem 1.125rem; } .pricing-table li:last-child { border-bottom: 0; } .pricing-table .title { background-color: #0a0a0a; color: #fefefe; border-bottom: 0; } .pricing-table .price { background-color: #e6e6e6; font-size: 2rem; border-bottom: 0; } .pricing-table .description { color: #8a8a8a; font-size: 80%; } .pricing-table :last-child { margin-bottom: 0; }
<h1> Hello World </h1>
Copyrights © - Joinc, All Rights Reserved. Inherited From - Yundream Rebranded By - Joonphil
Contents
Go 1.16 발표
embed package
embed 예제
Recent Posts
Archive Posts
Tags