Skip to content

Panic when calling local.E.GET(...) directly, but calling function value fn := local.E.GET works normally #975

@xsean2020

Description

@xsean2020
package main

import  echo "github.com/labstack/echo/v4"
import "fmt"
import "local"

// 定义一个 Scriggo 函数作为 Echo 的处理器
// 签名为 func(echo.Context) error
func HelloHandler(c echo.Context) error {
    name := c.QueryParam("name")
    if name == "" {
        name = "Guest"
    }

    // 返回 Go 的 (interface{}, error) 接口,Scriggo 会自动处理
    return c.String(200, "Hello from Scriggo: " + name)
}

// run 函数会拿到宿主传入的全局变量
// Scriggo 运行时会自动将 scriggo.Global 映射到 run 函数的参数
func main() {
    // 注册 GET /hello 路由
    fmt.Println("xxx-1", local.E == nil)
    fn := local.E.GET
    fn("/hello", HelloHandler)
    fmt.Println("init success by fn")
    local.E.GET("/hello2", HelloHandler)
    fmt.Println("init success local.E.GET")

    println("Scriggo: Routes registered successfully.", local.E == nil)
    local.E.Start(":28080")
}

init success by fn
panic: interface conversion: interface {} is []echo.MiddlewareFunc, not *runtime.callable

goroutine 22 [running]:
github.com/open2b/scriggo/internal/runtime.(*VM).Run(0x140002cc1e0?, 0x1?, 0x0?, {0x140002ca2b8?, 0x0?, 0x0?})
github.com/open2b/scriggo@v0.60.0/internal/runtime/vm.go:161 +0xb4
github.com/open2b/scriggo.(*Program).Run(0x140002d4510, 0x0)
github.com/open2b/scriggo@v0.60.0/programs.go:134 +0xc4
main.main.func1()
./main.go:83 +0x28
created by main.main in goroutine 1
./main.go:82 +0x22c
exit status 2

Metadata

Metadata

Assignees

No one assigned

    Labels

    InvalidBehaviorA valid or not valid code has an invalid behavior at runtimebugBug: something already implemented does not work as it shouldemitter/builderRelated to VM's emitter and builder

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions