[Go言語] jet,patを使った書き方 : static追加

$ tree
├── cmd
│   └── web
│   ├── main.go
│   └── routes.go
├── go.mod
├── go.sum
├── html
│   └── home.jet
├── internal
│   └── handlers
│   └── handlers.go
└── static
├── script.js
└── style.css

routes.go

package main

import (
	"webapp/internal/handlers"
	"net/http"

	"github.com/bmizerany/pat"
)

func routes() http.Handler {
	mux := pat.New()

	mux.Get("/", http.HandlerFunc(handlers.Home))

	fileServer := http.FileServer(http.Dir("./static/"))
	mux.Get("/static/", http.StripPrefix("/static", fileServer))
	return mux
}

home.jet

<head>
	<meta charset="UTF-8">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Document</title>
	<link rel="stylesheet" href="/static/style.css">
</head>
<body>
	<h1>jet test</h1>
	<script src="/static/scripts.js"></script>
</body>
</html>

scripts.js

alert("js is read")

sytle.css

h1 {
	color: orange;
}

なるほど