1
0
mirror of https://github.com/go-kratos/kratos.git synced 2026-05-16 09:48:28 +02:00
Files
kratos/examples/http/static/main.go
T
Tony Chen 1afbf70184 examples: add http examples (#822)
* add http examples
2021-04-12 21:37:16 +08:00

34 lines
588 B
Go

package main
import (
"embed"
"log"
"net/http"
"github.com/go-kratos/kratos/v2"
transhttp "github.com/go-kratos/kratos/v2/transport/http"
"github.com/gorilla/mux"
)
//go:embed assets/*
var f embed.FS
func main() {
router := mux.NewRouter()
// example: /assets/index.html
router.PathPrefix("/assets").Handler(http.FileServer(http.FS(f)))
httpSrv := transhttp.NewServer(transhttp.Address(":8000"))
httpSrv.HandlePrefix("/", router)
app := kratos.New(
kratos.Name("static"),
kratos.Server(
httpSrv,
),
)
if err := app.Run(); err != nil {
log.Println(err)
}
}