Skip to content

Instantly share code, notes, and snippets.

@NoobforAl
Created October 3, 2023 11:42
Show Gist options
  • Save NoobforAl/f972130a217e40cdff90f279594f20aa to your computer and use it in GitHub Desktop.
Save NoobforAl/f972130a217e40cdff90f279594f20aa to your computer and use it in GitHub Desktop.
Very Simple example templ go PKG
package main
templ hello(names []string) {
<div>
for _, name := range names {
<div>Hello,{ name }</div>
}
</div>
}
// for start program
// intsall templ: go install github.com/a-h/templ/cmd/templ@latest
// and go generate
// finaly run code : go run *.go
//go:generate templ generate
package main
import (
"fmt"
"net/http"
"github.com/a-h/templ"
)
func main() {
names := []string{"John", "Atlas", "Farhad"}
component := hello(names)
http.Handle("/", templ.Handler(component))
fmt.Println("http://localhost:3000")
_ = http.ListenAndServe("localhost:3000", nil)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment