command
Version:
v0.0.0-...-48f44c5
Opens a new window with list of versions in this module.
Published: Dec 9, 2024
License: Apache-2.0
Opens a new window with license information.
Imports: 8
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Using Adaptor to Work with jade
This example demonstrates how to use adaptor to integrate jade with Hertz as template engine.
Server
package main
//go:generate jade -pkg=main -writer hello.jade
import (
"context"
"fmt"
"github.com/cloudwego/hertz/pkg/app"
"github.com/cloudwego/hertz/pkg/app/server"
"github.com/cloudwego/hertz/pkg/common/adaptor"
)
func main() {
h := server.Default()
h.GET("/hello", func(ctx context.Context, c *app.RequestContext) {
req, err := adaptor.GetCompatRequest(&c.Request)
if err != nil {
return
}
// You may build more logic on req
fmt.Println(req.URL.String())
// caution: don't pass in c.GetResponse() as it return a copy of response
rw := adaptor.GetCompatResponseWriter(&c.Response)
Jade_hello("Hertz", rw)
})
h.Spin()
}
How to run
- install jade by running
go install github.com/Joker/jade/cmd/jade@latest
. Please refer to jade documentation should you require any help.
- run
jade -writer -pkg=main adaptor/jade/hello.jade
to generate go code from template file.
- run
go run hello/main.go
. This will spin up hertz listening on 8080.
- run
curl --location --request GET '127.0.0.1:8080/hello'
Documentation
¶
Code generated by "jade.go"; DO NOT EDIT.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.