mirror of
https://github.com/alibaba/higress.git
synced 2026-05-08 04:17:27 +08:00
Migrate WASM Go Plugins to New SDK and Go 1.24 (#2532)
This commit is contained in:
@@ -4,16 +4,18 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/alibaba/higress/plugins/wasm-go/pkg/wrapper"
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
"github.com/higress-group/proxy-wasm-go-sdk/proxywasm"
|
||||
"github.com/higress-group/proxy-wasm-go-sdk/proxywasm/types"
|
||||
"github.com/higress-group/wasm-go/pkg/log"
|
||||
"github.com/higress-group/wasm-go/pkg/wrapper"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// 自定义插件配置
|
||||
func main() {}
|
||||
|
||||
func main() {
|
||||
func init() {
|
||||
wrapper.SetCtx(
|
||||
"simple-jwt-auth", // 配置插件名称
|
||||
wrapper.ParseConfigBy(parseConfig),
|
||||
@@ -31,14 +33,14 @@ type Res struct {
|
||||
Msg string `json:"msg"` // 返回信息
|
||||
}
|
||||
|
||||
func parseConfig(json gjson.Result, config *Config, log wrapper.Log) error {
|
||||
func parseConfig(json gjson.Result, config *Config, log log.Log) error {
|
||||
// 解析出配置,更新到config中
|
||||
config.TokenSecretKey = json.Get("token_secret_key").String()
|
||||
config.TokenHeaders = json.Get("token_headers").String()
|
||||
return nil
|
||||
}
|
||||
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config Config, log wrapper.Log) types.Action {
|
||||
func onHttpRequestHeaders(ctx wrapper.HttpContext, config Config, log log.Log) types.Action {
|
||||
var res Res
|
||||
if config.TokenHeaders == "" || config.TokenSecretKey == "" {
|
||||
res.Code = http.StatusBadRequest
|
||||
|
||||
Reference in New Issue
Block a user